forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#50707 from diegs/json-ptr
Automatic merge from submit-queue (batch tested with PRs 50213, 50707, 49502, 51230, 50848) Fix forkedjson.LookupPatchMetadata for pointers. **What this PR does / why we need it**: Fixes a bug in `forkedjson.LookupPatchMetadata`. It is triggered when called with some API objects such as the `Selector` field (a pointer) in https://godoc.org/k8s.io/api/extensions/v1beta1#DeploymentSpec. The provided test case fails without the lines added to `fields.go`. **Which issue this PR fixes** N/A **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
staging/src/k8s.io/apimachinery/third_party/forked/golang/json/fields_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package json | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestLookupPtrToStruct(t *testing.T) { | ||
type Elem struct { | ||
Key string | ||
Value string | ||
} | ||
type Outer struct { | ||
Inner []Elem `json:"inner" patchStrategy:"merge" patchMergeKey:"key"` | ||
} | ||
outer := &Outer{} | ||
elemType, patchStrategies, patchMergeKey, err := LookupPatchMetadata(reflect.TypeOf(outer), "inner") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if elemType != reflect.TypeOf([]Elem{}) { | ||
t.Errorf("elemType = %v, want: %v", elemType, reflect.TypeOf([]Elem{})) | ||
} | ||
if !reflect.DeepEqual(patchStrategies, []string{"merge"}) { | ||
t.Errorf("patchStrategies = %v, want: %v", patchStrategies, []string{"merge"}) | ||
} | ||
if patchMergeKey != "key" { | ||
t.Errorf("patchMergeKey = %v, want: %v", patchMergeKey, "key") | ||
} | ||
} |