MCPcopy Create free account
hub / github.com/gavv/httpexpect / TestObject_Decode

Function TestObject_Decode

object_test.go:146–257  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestObject_Decode(t *testing.T) {
147 t.Run("target is empty interface", func(t *testing.T) {
148 reporter := newMockReporter(t)
149
150 m := map[string]interface{}{
151 "foo": 123.0,
152 "bar": []interface{}{"123", 234.0},
153 "baz": map[string]interface{}{
154 "a": "b",
155 },
156 }
157
158 value := NewObject(reporter, m)
159
160 var target interface{}
161 value.Decode(&target)
162
163 value.chain.assert(t, success)
164 assert.Equal(t, target, m)
165 })
166
167 t.Run("target is map", func(t *testing.T) {
168 reporter := newMockReporter(t)
169
170 m := map[string]interface{}{
171 "foo": 123.0,
172 "bar": []interface{}{"123", 234.0},
173 "baz": map[string]interface{}{
174 "a": "b",
175 },
176 }
177
178 value := NewObject(reporter, m)
179
180 var target map[string]interface{}
181 value.Decode(&target)
182
183 value.chain.assert(t, success)
184 assert.Equal(t, target, m)
185 })
186
187 t.Run("target is struct", func(t *testing.T) {
188 reporter := newMockReporter(t)
189
190 type S struct {
191 Foo int `json:"foo"`
192 Bar []interface{} `json:"bar"`
193 Baz map[string]interface{} `json:"baz"`
194 Bat struct{ A int } `json:"bat"`
195 }
196
197 m := map[string]interface{}{
198 "foo": 123,
199 "bar": []interface{}{"123", 234.0},
200 "baz": map[string]interface{}{
201 "a": "b",
202 },
203 "bat": struct{ A int }{123},

Callers

nothing calls this directly

Calls 5

DecodeMethod · 0.95
newMockReporterFunction · 0.85
NewObjectFunction · 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…