IsEqual succeeds if object is equal to given value. Before comparison, both object and value are converted to canonical form. value should be map[string]interface{} or struct. Example: object := NewObject(t, map[string]interface{}{"foo": 123}) object.IsEqual(map[string]interface{}{"foo": 123})
(value interface{})
| 809 | // object := NewObject(t, map[string]interface{}{"foo": 123}) |
| 810 | // object.IsEqual(map[string]interface{}{"foo": 123}) |
| 811 | func (o *Object) IsEqual(value interface{}) *Object { |
| 812 | opChain := o.chain.enter("IsEqual()") |
| 813 | defer opChain.leave() |
| 814 | |
| 815 | if opChain.failed() { |
| 816 | return o |
| 817 | } |
| 818 | |
| 819 | expected, ok := canonMap(opChain, value) |
| 820 | if !ok { |
| 821 | return o |
| 822 | } |
| 823 | |
| 824 | if !reflect.DeepEqual(expected, o.value) { |
| 825 | opChain.fail(AssertionFailure{ |
| 826 | Type: AssertEqual, |
| 827 | Actual: &AssertionValue{o.value}, |
| 828 | Expected: &AssertionValue{expected}, |
| 829 | Errors: []error{ |
| 830 | errors.New("expected: maps are equal"), |
| 831 | }, |
| 832 | }) |
| 833 | } |
| 834 | |
| 835 | return o |
| 836 | } |
| 837 | |
| 838 | // NotEqual succeeds if object is not equal to given value. |
| 839 | // Before comparison, both object and value are converted to canonical form. |