go-testdeep Cmp shortcuts
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 := td.Must(CreateRecord("Bob", 23))
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://go.dev/play/p/GS9G-g2ePr8