Skip to content

Commit

Permalink
chore: add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jferrl committed Apr 27, 2024
1 parent 7a515cc commit 2999949
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions yo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ func TestModel_Apply(t *testing.T) {
mutType: Update,
wantErr: true,
},
{
name: "before insert hook returns an error",
fields: fields{model: model},
mutType: Insert,
before: func(_ context.Context, m *Model[*user.User], _ *spanner.ReadWriteTransaction) error {
return errors.New("before insert hook error")
},
wantErr: true,
},
{
name: "after insert hook returns an error",
fields: fields{model: model},
mutType: Insert,
after: func(_ context.Context, m *Model[*user.User], _ *spanner.ReadWriteTransaction) error {
return errors.New("after insert hook error")
},
wantErr: true,
},
{
name: "insert a new user into the database with hooks",
fields: fields{model: model},
Expand Down Expand Up @@ -139,6 +157,16 @@ func TestModel_Apply(t *testing.T) {
},
},
},
{
name: "delete a user from the database when is created with before delete hook",
fields: fields{model: model},
mutType: Delete,
before: func(cxt context.Context, m *Model[*user.User], txn *spanner.ReadWriteTransaction) error {
return txn.BufferWrite([]*spanner.Mutation{
m.Insert(cxt),
})
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 2999949

Please sign in to comment.