Test a map[string]interface{} with ginkgo and gomega

1.1k views Asked by At

During testing I get the error message

Expected
        <[]map[string]interface {} | len:0, cap:0>: []
    to equal
        <[]map[string]interface {} | len:0, cap:0>: nil

How Do i declare a []map[string]interface {} to be "nil"?

thank you

1

There are 1 answers

0
advay rajhansa On

You can use the gomega matchers like this:

Describe("the test", func() {
    var obj []map[string]interface{}

    It("should be nil", func() {
        Expect(obj).To(BeNil())
    })

    It("should be empty []", func() {
        Expect(obj).To(BeEmpty())
    })
})

These tests will pass if the value is not initialized also.

This is how you can declare the map[string]interface{} to be nil:

var obj []map[string]interface{}
// OR
var obj []map[string]interface{} = nil