smartystreets / goconvey

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.
http://smartystreets.github.io/goconvey/
Other
8.23k stars 555 forks source link

ShouldEqual can't compare same value for custom type #524

Open mrLSD opened 6 years ago

mrLSD commented 6 years ago

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.

Dieterbe commented 6 years ago

also running into this. i have 2 values that are most definitely identical, yet ShouldEqual claims they aren't.

dsmontoya commented 6 years ago

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)
sbasile-ch commented 5 years ago

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"))
            })
        })
    })
}
error
Albelt commented 2 years ago

Same problem, but I just found that the documentation has already metioned this point 😅
https://github.com/smartystreets/goconvey/wiki/Assertions#general-equality