Skip to content

Commit

Permalink
Improve unit tests according to changes in DATA-DOG/go-sqlmock. (#729)
Browse files Browse the repository at this point in the history
Improve unit tests according to changes in DATA-DOG/go-sqlmock.
  • Loading branch information
dsuhinin authored Dec 11, 2023
1 parent 9e47df6 commit 1cd2a15
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/api/mlflow/dao/repositories/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func Test_renumberRows(t *testing.T) {
//nolint:errcheck
defer mockDb.Close()

lockExpect := func() {
mock.ExpectExec("LOCK TABLE runs").WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec(`UPDATE runs`).WillReturnResult(sqlmock.NewResult(0, 1))
}

dialector := postgres.New(postgres.Config{
Conn: mockDb,
DriverName: "postgres",
Expand All @@ -55,12 +50,21 @@ func Test_renumberRows(t *testing.T) {
for _, tc := range testData {
t.Run(tc.name, func(t *testing.T) {
if tc.startWith < 0 {
err := repo.renumberRows(db, tc.startWith)
assert.EqualError(t, err, "attempting to renumber with less than 0 row number value")
assert.EqualError(
t,
repo.renumberRows(db, tc.startWith),
"attempting to renumber with less than 0 row number value",
)
} else {
lockExpect()
err := repo.renumberRows(db, tc.startWith)
assert.NoError(t, err)
mock.ExpectExec(
"LOCK TABLE runs",
).WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec(`UPDATE runs`).WithArgs(
tc.startWith, tc.startWith,
).WillReturnResult(
sqlmock.NewResult(0, 1),
)
assert.NoError(t, repo.renumberRows(db, tc.startWith))
}
})
}
Expand Down

0 comments on commit 1cd2a15

Please sign in to comment.