HasValue succeeds if object's value for given key is equal to given value. Before comparison, both values are converted to canonical form. value should be map[string]interface{} or struct. Example: object := NewObject(t, map[string]interface{}{"foo": 123}) object.HasValue("foo", 123)
(key string, value interface{})
| 246 | // object := NewObject(t, map[string]interface{}{"foo": 123}) |
| 247 | // object.HasValue("foo", 123) |
| 248 | func (o *Object) HasValue(key string, value interface{}) *Object { |
| 249 | opChain := o.chain.enter("HasValue(%q)", key) |
| 250 | defer opChain.leave() |
| 251 | |
| 252 | if opChain.failed() { |
| 253 | return o |
| 254 | } |
| 255 | |
| 256 | if !containsKey(opChain, o.value, key) { |
| 257 | opChain.fail(AssertionFailure{ |
| 258 | Type: AssertContainsKey, |
| 259 | Actual: &AssertionValue{o.value}, |
| 260 | Expected: &AssertionValue{key}, |
| 261 | Errors: []error{ |
| 262 | errors.New("expected: map contains key"), |
| 263 | }, |
| 264 | }) |
| 265 | return o |
| 266 | } |
| 267 | |
| 268 | expected, ok := canonValue(opChain, value) |
| 269 | if !ok { |
| 270 | return o |
| 271 | } |
| 272 | |
| 273 | if !reflect.DeepEqual(expected, o.value[key]) { |
| 274 | opChain.fail(AssertionFailure{ |
| 275 | Type: AssertEqual, |
| 276 | Actual: &AssertionValue{o.value[key]}, |
| 277 | Expected: &AssertionValue{value}, |
| 278 | Errors: []error{ |
| 279 | fmt.Errorf( |
| 280 | "expected: map value for key %q is equal to given value", |
| 281 | key), |
| 282 | }, |
| 283 | }) |
| 284 | return o |
| 285 | } |
| 286 | |
| 287 | return o |
| 288 | } |
| 289 | |
| 290 | // NotHasValue succeeds if object's value for given key is not equal to given |
| 291 | // value. Before comparison, both values are converted to canonical form. |
no test coverage detected