github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/third_party/forked/golang/json/fields_test.go (about)

     1  package json
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestLookupPtrToStruct(t *testing.T) {
     9  	type Elem struct {
    10  		Key   string
    11  		Value string
    12  	}
    13  	type Outer struct {
    14  		Inner []Elem `json:"inner" patchStrategy:"merge" patchMergeKey:"key"`
    15  	}
    16  	outer := &Outer{}
    17  	elemType, patchStrategies, patchMergeKey, err := LookupPatchMetadataForStruct(reflect.TypeOf(outer), "inner")
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  	if elemType != reflect.TypeOf([]Elem{}) {
    22  		t.Errorf("elemType = %v, want: %v", elemType, reflect.TypeOf([]Elem{}))
    23  	}
    24  	if !reflect.DeepEqual(patchStrategies, []string{"merge"}) {
    25  		t.Errorf("patchStrategies = %v, want: %v", patchStrategies, []string{"merge"})
    26  	}
    27  	if patchMergeKey != "key" {
    28  		t.Errorf("patchMergeKey = %v, want: %v", patchMergeKey, "key")
    29  	}
    30  }