The Cmp
function is the keystone of this package, but to make the writing of
tests even easier, the family of Cmp*
functions are provided and act as shortcuts. Using
CmpStruct
function, the previous example can be written as:
import (
"testing"
"time"
"github.com/maxatome/go-testdeep/td"
)
func TestCreateRecord(t *testing.T) {
before := time.Now().Truncate(time.Second)
record, err := CreateRecord("Bob", 23)
if td.CmpNoError(t, err) {
td.CmpStruct(t, record,
&Record{
Name: "Bob",
Age: 23,
},
td.StructFields{
"Id": td.NotZero(),
"CreatedAt": td.Between(before, time.Now()),
},
"Newly created record")
}
}
Test it in playground: https://play.golang.org/p/d2FxGASUa_B