MCPcopy Index your code
hub / github.com/gavv/httpexpect / TestArray_Decode

Function TestArray_Decode

array_test.go:149–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

147}
148
149func TestArray_Decode(t *testing.T) {
150 t.Run("target is empty interface", func(t *testing.T) {
151 reporter := newMockReporter(t)
152
153 testValue := []interface{}{"Foo", 123.0}
154 arr := NewArray(reporter, testValue)
155
156 var target interface{}
157 arr.Decode(&target)
158
159 arr.chain.assert(t, success)
160 assert.Equal(t, testValue, target)
161 })
162
163 t.Run("target is slice of empty interfaces", func(t *testing.T) {
164 reporter := newMockReporter(t)
165
166 testValue := []interface{}{"Foo", 123.0}
167 arr := NewArray(reporter, testValue)
168
169 var target []interface{}
170 arr.Decode(&target)
171
172 arr.chain.assert(t, success)
173 assert.Equal(t, testValue, target)
174 })
175
176 t.Run("target is slice of structs", func(t *testing.T) {
177 reporter := newMockReporter(t)
178
179 type S struct {
180 Foo int `json:"foo"`
181 }
182
183 actualStruct := []S{{123}, {456}}
184 testValue := []interface{}{
185 map[string]interface{}{
186 "foo": 123,
187 },
188 map[string]interface{}{
189 "foo": 456,
190 },
191 }
192 arr := NewArray(reporter, testValue)
193
194 var target []S
195 arr.Decode(&target)
196
197 arr.chain.assert(t, success)
198 assert.Equal(t, actualStruct, target)
199 })
200
201 t.Run("target is unmarshable", func(t *testing.T) {
202 reporter := newMockReporter(t)
203
204 testValue := []interface{}{"Foo", 123.0}
205 arr := NewArray(reporter, testValue)
206

Callers

nothing calls this directly

Calls 5

DecodeMethod · 0.95
newMockReporterFunction · 0.85
NewArrayFunction · 0.85
assertMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…