Golang:reflect.DeepEqual返回意外的false

Golang:reflect.DeepEqual返回意外的false,go,testing,tdd,Go,Testing,Tdd,我有下面的代码和代码测试,由于某种原因,deepEqual返回了一个false,测试失败。现在,通过阅读关于这个的文档,我希望它能以一个真实的形式通过,对于这么简单的事情?任何要点都将不胜感激。谢谢 // customer.go type Customer struct { customerID int domains []string names []string } func NewCustomer(customerID int, domains []string,

我有下面的代码和代码测试,由于某种原因,deepEqual返回了一个false,测试失败。现在,通过阅读关于这个的文档,我希望它能以一个真实的形式通过,对于这么简单的事情?任何要点都将不胜感激。谢谢

// customer.go
type Customer struct {
    customerID int
    domains []string
    names []string
}
func NewCustomer(customerID int, domains []string, names []string) *Customer{
    return &Customer{
        customerID: customerID,
        domains: domains,
        names:names,
    }
}
输出:

Got: &{123 [] []}, expected: &{123 [] []}
reflect.DeepEqual()
按预期返回
true
,这就是调用
t.Errorf()
的原因

如果它们不相等,则希望测试失败。您只需否定该条件:

if !reflect.DeepEqual(got, expected) {
    t.Errorf("Got: %v, expected: %v", got, expected)
}
if !reflect.DeepEqual(got, expected) {
    t.Errorf("Got: %v, expected: %v", got, expected)
}