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

Method NotHasValue

object.go:302–342  ·  view source on GitHub ↗

NotHasValue succeeds if object's value for given key is not equal to given value. Before comparison, both values are converted to canonical form. value should be map[string]interface{} or struct. If object doesn't contain any value for given key, failure is reported. Example: object := NewObjec

(key string, value interface{})

Source from the content-addressed store, hash-verified

300// object.NotHasValue("foo", "bad value") // success
301// object.NotHasValue("bar", "bad value") // failure! (key is missing)
302func (o *Object) NotHasValue(key string, value interface{}) *Object {
303 opChain := o.chain.enter("NotHasValue(%q)", key)
304 defer opChain.leave()
305
306 if opChain.failed() {
307 return o
308 }
309
310 if !containsKey(opChain, o.value, key) {
311 opChain.fail(AssertionFailure{
312 Type: AssertContainsKey,
313 Actual: &AssertionValue{o.value},
314 Expected: &AssertionValue{key},
315 Errors: []error{
316 errors.New("expected: map contains key"),
317 },
318 })
319 return o
320 }
321
322 expected, ok := canonValue(opChain, value)
323 if !ok {
324 return o
325 }
326
327 if reflect.DeepEqual(expected, o.value[key]) {
328 opChain.fail(AssertionFailure{
329 Type: AssertNotEqual,
330 Actual: &AssertionValue{o.value[key]},
331 Expected: &AssertionValue{value},
332 Errors: []error{
333 fmt.Errorf(
334 "expected: map value for key %q is non-equal to given value",
335 key),
336 },
337 })
338 return o
339 }
340
341 return o
342}
343
344// Deprecated: use HasValue instead.
345func (o *Object) ValueEqual(key string, value interface{}) *Object {

Callers 1

ValueNotEqualMethod · 0.95

Calls 7

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

Tested by

no test coverage detected