Ginkgo Receive(BeEquivalentTo()) fails when comparing struct with interface payload
04:58 07 Nov 2025

When writing Ginkgo unit tests, I ran into an issue asserting data received from a channel that contains a struct with an interface{} field.
Here's my models.go

type WsBaseMsg struct {
    Type    string      `json:"type"` // Discriminator field
    Payload interface{} `json:"payload"`
}

type WsRegistryMsg struct {
    Services LoginsResp
}

type LoginsResp struct {
    Service string    `json:"service"`
    Date    time.Time `json:"date"`
}

And here's ginkgo unit test

expectedMsg := models.WsBaseMsg{
    Type: "NewLogin",
    Payload: []*models.LoginsResp{
    {
        Service: "SomeService",
        Date:    time.Date(2025, time.October, 26, 14, 0, 0, 0, time.UTC),
    },
},
}

wg.Add(1)
go func() {
    defer GinkgoRecover()
    defer wg.Done()
    LoginService.FindLogins(ctx, mockUser, mockConn, resultChan, errChan)}()


Consistently(resultChan,1*time.Second).Should(Receive(BeEquivalentTo(expectedMsg)))

Above FindLogins() returns something like this

: {
          Type: "NewLogin",
          Payload: <[]*models.LoginsResp | len:1, cap:1>[
              {
                  Service: "SomeService",
                  Date: 2025-10-26T14:00:00Z,
              },
          ],
      }

But that assertion failed and give me this message:

RegistersServiceTest FindLoginsServiceTest [It] it should continiously add results channel
/home/cybercrow/Documents/Projects/micro-saas/WhereIDo/server/test/registers_test.go:157

  [FAILED] Failed after 0.000s.
  Expected
      : {
          Type: "NewLogin",
          Payload: <[]*models.LoginsResp | len:1, cap:1>[
              {
                  Service: "SomeService",
                  Date: 2025-10-26T14:00:00Z,
              },
          ],
      }
  to be equivalent to
      : {
          Type: "NewLogin",
          Payload: <[]*models.LoginsResp | len:1, cap:1>[
              {
                  Service: "SomeService",
                  Date: 2025-10-26T14:00:00Z,
              },
          ],
      }

Why assertion failed even expected message comes from that function.

unit-testing go ginkgo