Slide 26
Slide 26 text
26
func TestGetToDoByID(t *testing.T) {
t.Parallel()
tx, cleanup := TestSetupTx(t)
defer cleanup()
testShowCount(t, tx)
td := TestCreateToDo(t, tx, &ToDo{
Description: "test",
Status: "created",
})
cases := []struct {
id int64
found bool
}{
{id: td.ID, found: true},
{id: 0, found: false},
}
for _, c := range cases {
td, found, err := GetToDoByID(tx, c.id)
if err != nil {
t.Fatal(err)
}
if found != c.found {
t.Errorf("want %t got %t", c.found, found)
}
if found && td.ID != c.id {
t.Errorf("want %d got %d", c.id, td.ID)
}
}
testShowCount(t, tx)
}