How do you change the "Cap" value of an []map[string]interface{} in go lang?

330 views Asked by At

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

1

There are 1 answers

9
advay rajhansa On

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