Skip to content
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

ShouldResemble fails on map[string]interface{} #437

Closed
ThomasJannaud opened this issue Jul 21, 2016 · 6 comments
Closed

ShouldResemble fails on map[string]interface{} #437

ThomasJannaud opened this issue Jul 21, 2016 · 6 comments

Comments

@ThomasJannaud
Copy link

ThomasJannaud commented Jul 21, 2016

Hi
I don't know if ShouldResemble is supposed to work there but I get this

  Line 36:
  Expected: 'model.A{UID:"joe", CID:"cid", Metadata:map[string]interface{}{"key":"value string", "key array":[]interface{}{2, "blabla"}, "key int":3}}'
  Actual:   'model.A{UID:"joe", CID:"cid", Metadata:map[string]interface{}{"key":"value string", "key array":[]interface{}{2, "blabla"}, "key int":3}}'
  (Should resemble)!

My struct:

    A{
        UID:      "joe",
        CID:      "cid",
        Metadata: map[string]interface{}{
            "key": "value string",
            "key int": 3,
            "key array":[]interface{}{2, "blabla"},
        },
    }

Note that if I remove the"key int" and "key array" the test passes

@bunkat
Copy link

bunkat commented Nov 7, 2016

I just ran into this as well:

Line 818:
  Expected: 'map[string]interface{}{"basecost":12000, "basemin":60, "initialcost":0, "initialmin":0, "overtimecost":0, "overtimemin":0}'
  Actual:   'map[string]interface{}{"basecost":12000, "basemin":60, "initialcost":0, "initialmin":0, "overtimecost":0, "overtimemin":0}'
  (Should resemble)!

@rafael84
Copy link

Same here:

Line 44:
Expected: 'map[string]interface{}{"fields":[]string{}, "limit":25, "offset":0}'
Actual:   'map[string]interface{}{"fields":[]string{}, "limit":25, "offset":0}'
(Should resemble)!

@haozeng
Copy link

haozeng commented Mar 1, 2017

what about ?


  Expected: '[{"op":"replace","path":"/baz","value":"boo"},{"op":"add","path":"/hello","value":["world"]},{"op":"remove","path":"/foo"}]'
  Actual:   '[{"op":"add","path":"/hello","value":["world"]},{"op":"replace","path":"/baz","value":"boo"},{"op":"remove","path":"/foo"}]'

which is the right assertion matcher to use?

@benpaxton-hf
Copy link

benpaxton-hf commented Mar 2, 2017

I've seen this too when asserting an object unmarshaled into a map[string]interface{} via json.Unmarshal; the fix is to use literal float64s, instead of integers:

var obj map[string]interface{}
_ = json.Unmarshal([]byte(`{"a_number": 3}`), &obj)

fmt.Printf("%T\n", obj["a_number"]) // "float64"

So(obj, ShouldResemble, map[string]interface{}{"a_number": 3}) // fail
So(obj, ShouldResemble, map[string]interface{}{"a_number": 3.0}) // pass
So(obj, ShouldResemble, map[string]interface{}{"a_number": float64(3)}) // pass

ShouldResemble compares types first, then values; if the types aren't equal, it fails.

This also affects eg using aliases for types, such as type M map[string]interface{} (#473)

@mdwhatcott
Copy link
Collaborator

mdwhatcott commented Jul 21, 2017

This issue is more related to the assertions package than to GoConvey so I've moved it there.

@benpaxton-hf
Copy link

@mdwhatcott that likely applies to #473 too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants