1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package expectate_test
import (
"testing"
"time"
"github.com/gomagedon/expectate"
"github.com/google/go-cmp/cmp"
)
var toEqualTests = []ExpectTest{
{
name: "2 equals 2",
subject: 2,
object: 2,
expectedFailure: "",
},
{
name: "2 does not equal 3",
subject: 2,
object: 3,
expectedFailure: cmp.Diff(3, 2),
},
{
name: "'foo' equals 'foo'",
subject: "foo",
object: "foo",
expectedFailure: "",
},
{
name: "'foo' does not equal 'bar'",
subject: "foo",
object: "bar",
expectedFailure: cmp.Diff("bar", "foo"),
},
{
name: "pointer to struct is pointer to copy of struct",
subject: &Person{
Name: "John Doe",
Age: 30,
Job: "Electrician",
Birthday: time.Date(1990, time.January, 1, 0, 0, 0, 0, time.UTC),
},
object: &Person{
Name: "John Doe",
Age: 30,
Job: "Electrician",
Birthday: time.Date(1990, time.January, 1, 0, 0, 0, 0, time.UTC),
},
expectedFailure: "",
},
}
func TestToEqual(t *testing.T) {
for _, test := range toEqualTests {
t.Run(test.name, func(t *testing.T) {
mockTestingT := new(MockTestingT)
expect := expectate.Expect(mockTestingT)
expect(test.subject).ToEqual(test.object)
if mockTestingT.FataledWith != test.expectedFailure {
t.Fatal("Expected:", test.expectedFailure,
"\nGot:", mockTestingT.FataledWith)
}
})
}
}
|