Selvatico / go-mocket

Go GORM & SQL mocking library
MIT License
220 stars 36 forks source link

RowsAffected not set during INSERT statement match #29

Open hamersaw opened 3 years ago

hamersaw commented 3 years ago

I have the following code testing an INSERT. The goal is to simulate a key already exists; which, when specified with 'ON CONFLICT DO NOTHING' returns no error and instead just RowsAffected() on the result returns 0.

GlobalMock := mocket.Catcher.Reset()
GlobalMock.Logging = true
expectedReservation := GetReservation()

GlobalMock.NewMock().WithQuery(
    `INSERT INTO "reservations" ("created_at","updated_at","deleted_at","dataset_project","dataset_name","dataset_domain","dataset_version","tag_name","owner_id","expires_at","serialized_metadata") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) ON CONFLICT DO NOTHING`,
).WithRowsNum(0)

What I am seeing is that no matter what I change the WithRowsNum() called value to the RowsAffected always returns 1. This same syntax works well in testing an UPDATE command, so it's peculiar that it is not working here. Any thoughts?