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

Method HasValue

array.go:203–246  ·  view source on GitHub ↗

HasValue succeeds if array's value at the given index is equal to given value. Before comparison, both values are converted to canonical form. value should be map[string]interface{} or struct. Example: array := NewArray(t, []interface{}{"foo", "123"}) array.HasValue(1, 123)

(index int, value interface{})

Source from the content-addressed store, hash-verified

201// array := NewArray(t, []interface{}{"foo", "123"})
202// array.HasValue(1, 123)
203func (a *Array) HasValue(index int, value interface{}) *Array {
204 opChain := a.chain.enter("HasValue(%d)", index)
205 defer opChain.leave()
206
207 if opChain.failed() {
208 return a
209 }
210
211 if index < 0 || index >= len(a.value) {
212 opChain.fail(AssertionFailure{
213 Type: AssertInRange,
214 Actual: &AssertionValue{index},
215 Expected: &AssertionValue{AssertionRange{
216 Min: 0,
217 Max: len(a.value) - 1,
218 }},
219 Errors: []error{
220 errors.New("expected: valid element index"),
221 },
222 })
223 return a
224 }
225
226 expected, ok := canonValue(opChain, value)
227 if !ok {
228 return a
229 }
230
231 if !reflect.DeepEqual(expected, a.value[index]) {
232 opChain.fail(AssertionFailure{
233 Type: AssertEqual,
234 Actual: &AssertionValue{a.value[index]},
235 Expected: &AssertionValue{value},
236 Errors: []error{
237 fmt.Errorf(
238 "expected: array value at index %d is equal to given value",
239 index),
240 },
241 })
242 return a
243 }
244
245 return a
246}
247
248// NotHasValue succeeds if array's value at the given index is not equal to given value.
249//

Callers 14

TestArray_FailedChainFunction · 0.45
TestArray_HasValueFunction · 0.45
TestExpect_TraverseFunction · 0.45
TestObject_FailedChainFunction · 0.45
TestObject_HasValueFunction · 0.45
TestWsHandlerJSONFunction · 0.45
TestWsFastHandlerJSONFunction · 0.45
TestIrisRedirectFunction · 0.45
TestIrisParamsFunction · 0.45
TestGinHandlerFunction · 0.45
TestFruitsFunction · 0.45

Calls 6

canonValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80
ErrorfMethod · 0.65

Tested by 14

TestArray_FailedChainFunction · 0.36
TestArray_HasValueFunction · 0.36
TestExpect_TraverseFunction · 0.36
TestObject_FailedChainFunction · 0.36
TestObject_HasValueFunction · 0.36
TestWsHandlerJSONFunction · 0.36
TestWsFastHandlerJSONFunction · 0.36
TestIrisRedirectFunction · 0.36
TestIrisParamsFunction · 0.36
TestGinHandlerFunction · 0.36
TestFruitsFunction · 0.36