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{})
| 300 | // object.NotHasValue("foo", "bad value") // success |
| 301 | // object.NotHasValue("bar", "bad value") // failure! (key is missing) |
| 302 | func (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. |
| 345 | func (o *Object) ValueEqual(key string, value interface{}) *Object { |
no test coverage detected