@@ -77,3 +77,76 @@ func TestToUnstructured(t *testing.T) {
77
77
})
78
78
}
79
79
}
80
+
81
+ func TestTypeReflectEntryOf (t * testing.T ) {
82
+ testString := ""
83
+ tests := map [string ]struct {
84
+ arg interface {}
85
+ want * TypeReflectCacheEntry
86
+ }{
87
+ "StructWithStringField" : {
88
+ arg : struct {
89
+ F1 string `json:"f1"`
90
+ }{},
91
+ want : & TypeReflectCacheEntry {
92
+ structFields : map [string ]* FieldCacheEntry {
93
+ "f1" : {
94
+ JsonName : "f1" ,
95
+ fieldPath : [][]int {{0 }},
96
+ fieldType : reflect .TypeOf (testString ),
97
+ TypeEntry : & TypeReflectCacheEntry {},
98
+ },
99
+ },
100
+ orderedStructFields : []* FieldCacheEntry {
101
+ {
102
+ JsonName : "f1" ,
103
+ fieldPath : [][]int {{0 }},
104
+ fieldType : reflect .TypeOf (testString ),
105
+ TypeEntry : & TypeReflectCacheEntry {},
106
+ },
107
+ },
108
+ },
109
+ },
110
+ "StructWith*StringFieldOmitempty" : {
111
+ arg : struct {
112
+ F1 * string `json:"f1,omitempty"`
113
+ }{},
114
+ want : & TypeReflectCacheEntry {
115
+ structFields : map [string ]* FieldCacheEntry {
116
+ "f1" : {
117
+ JsonName : "f1" ,
118
+ isOmitEmpty : true ,
119
+ fieldPath : [][]int {{0 }},
120
+ fieldType : reflect .TypeOf (& testString ),
121
+ TypeEntry : & TypeReflectCacheEntry {},
122
+ },
123
+ },
124
+ orderedStructFields : []* FieldCacheEntry {
125
+ {
126
+ JsonName : "f1" ,
127
+ isOmitEmpty : true ,
128
+ fieldPath : [][]int {{0 }},
129
+ fieldType : reflect .TypeOf (& testString ),
130
+ TypeEntry : & TypeReflectCacheEntry {},
131
+ },
132
+ },
133
+ },
134
+ },
135
+ "StructWithInlinedField" : {
136
+ arg : struct {
137
+ F1 string `json:",inline"`
138
+ }{},
139
+ want : & TypeReflectCacheEntry {
140
+ structFields : map [string ]* FieldCacheEntry {},
141
+ orderedStructFields : []* FieldCacheEntry {},
142
+ },
143
+ },
144
+ }
145
+ for name , tt := range tests {
146
+ t .Run (name , func (t * testing.T ) {
147
+ if got := TypeReflectEntryOf (reflect .TypeOf (tt .arg )); ! reflect .DeepEqual (got , tt .want ) {
148
+ t .Errorf ("TypeReflectEntryOf() = %v, want %v" , got , tt .want )
149
+ }
150
+ })
151
+ }
152
+ }
0 commit comments