-
-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparing interface{} #161
Comments
I agree, it took me a bit to clue in on this. I received this when using json. |
Hey @heynemann and @rlubke I've just started trying to go through abandoned issues. I could take a guess at what this is about but it would be really awesome if either of you had some simple reproduction code. Thanks! |
I have tried to reproduce the problem with It("succeeds", func() {
j := `[1,2]`
var slice []interface{}
json.Unmarshal([]byte(j), &slice)
same := []interface{}{1, 2}
Expect(slice).To(BeEquivalentTo(same))
}) The output is:
The example above fails because
You should see: I have tried the same with the package It("succeeds msgpack", func() {
in := []int{1, 2}
b, _ := msgpack.Marshal(in)
var slice []interface{}
msgpack.Unmarshal(b, &slice)
same := []interface{}{1, 2}
fmt.Printf("%T vs %T\n", same[0], slice[0])
Expect(slice).To(BeEquivalentTo(same))
}) outputs:
In this case Hope it helps @heynemann |
Great investigation @nodo. Wondering if there's any way we can provide better feedback to the message, it sure does suck when things are visually the same but not actually. |
Yes, it does! I think you are right @williammartin, it would be a good idea to change the message. We could add some logic when printing the types of the objects: https://github.com/onsi/gomega/blob/master/format/format.go#L191 For instance: case reflect.Slice:
v := reflect.ValueOf(object)
output := fmt.Sprintf("%T | len:%d, cap:%d", object, v.Len(), v.Cap())
if v.Len() > 0 {
a := object.([]interface{})
output = fmt.Sprintf("%s | Slice of %T", output, a[0])
}
return output I think the message would be clearer:
What do you think? Too hacky? |
No I think that would provide some useful clarity @nodo. Can you PR? |
Maybe
|
Sure, I can give it a go! |
I am still not sure on how to format the concrete types of the elements of the slice. Do you think we should list them? It does not feel right to me. |
@nodo Did you have any more thoughts on this? |
@nodo Any thoughts? |
When comparing two items for equivalence I get this error:
I only get this when deserializing a []int{1, 2} from messagepack. I'm sure the types are at fault here, but the message could improve IMHO.
The text was updated successfully, but these errors were encountered: