0

I am trying to do some testing with ginkgo and gomega, I get down to the assertion error

Expected
        <[]map[string]interface {} | len:1, cap:1>: []
To equal
        <[]map[string]interface {} | len:1, cap:4>: []

I believe that the test is failing because they do not have equal "cap" values, Is there a way to make these cap values equal? Also, would having the items be in different orders cause these test to fail?

thank you

3
  • What is ginko, what is gomega? And no, you cannot control cap of a (used) map. Commented Apr 27, 2021 at 5:16
  • ginko is BDD Testing framework and gomega is matcher/assertion library which goes in hand Commented Apr 27, 2021 at 5:19
  • tour.golang.org/moretypes/13 has an example of making an array with non-default capacity. You might want something like make([]map[string]interface{}, 1, 4). Commented Apr 27, 2021 at 14:30

1 Answer 1

0

This shows that you have a slice of maps which had some data. This data is now removed. But slice capacity won't decrease. If you need to check if slice is empty, you can go to BeEmpty gomega matcher.

If you want an empty slice with known capacity, you can do it like:

obj := make([]map[string]interface{}, 4) // 4 is size you need
Sign up to request clarification or add additional context in comments.

9 Comments

How would I add data to this after initializiation?
obj[0] = your map
previously i had it declared like ` expected = []map[string]interface{}{ { "name": expectedCompany.Name, "orders": [] interface {} } } ` but declaring it like this doesn't seem to work with the new make 4
obj[0] = map[string]interface{}{ "name": your data }
I get expected operand, found '{'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.