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

benwasin97
  • 203
  • 4
  • 12
  • What is ginko, what is gomega? And no, you cannot control cap of a (used) map. – Volker Apr 27 '21 at 05:16
  • ginko is BDD Testing framework and gomega is matcher/assertion library which goes in hand – advay rajhansa Apr 27 '21 at 05:19
  • https://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)`. – Tinkerer Apr 27 '21 at 14:30

1 Answers1

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
advay rajhansa
  • 1,129
  • 9
  • 17