goconvey
goconvey copied to clipboard
ShouldEqual can't compare same value for custom type
ShouldEqual can't compare same value for custom type
Examples:
t := time.Now()
So(t, ShouldEqual, t)
And:
type test struct {
A string
}
a1 := test{"test"}
So(a1, ShouldEqual, a1)
All of them returns FAILED.
also running into this. i have 2 values that are most definitely identical, yet ShouldEqual claims they aren't.
When deep equal check is required, use ShouldResemble instead
type test struct {
A string
}
a1 := test{"test"}
a2 := test{"test"}
a3 := test{"sup"}
So(a1, ShouldResemble, a2)
So(a1, ShouldResemble, a3)
Same issue (even using latest commit available (044398e)).
ShouldEqual doesn't work for type error while ShouldResemble did the trick.
//-------------------------------- service.go:
package main
import "errors"
func doSomething() (err error) {
err = errors.New("a2")
return
}
//-------------------------------- service_test.go:
package main
import (
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestDoSomething1(t *testing.T) {
Convey("Given", t, func() {
Convey("When", func() {
Convey("Then", func() {
err := doSomething()
So(err, ShouldEqual, errors.New("a2"))
})
})
})
}
Same problem, but I just found that the documentation has already metioned this point 😅
https://github.com/smartystreets/goconvey/wiki/Assertions#general-equality