-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: delete first run in aim ui (#158) * Add integration test to delete first run - row 0 * Change Errorf to New * Add unit test to test for negative row number in renumberRows * gofmt run_test * Add cases for (-1,0,1) * Use proper format for test --------- Co-authored-by: Geoffrey Wilson <[email protected]> Co-authored-by: Software Developer <[email protected]>
- Loading branch information
1 parent
a92e205
commit 3dc9e2b
Showing
6 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package repositories | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/DATA-DOG/go-sqlmock.v1" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
|
||
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models" | ||
) | ||
|
||
func Test_renumberRows(t *testing.T) { | ||
testData := []struct { | ||
name string | ||
startWith models.RowNum | ||
}{ | ||
{ | ||
name: "NegativeRowNumber", | ||
startWith: models.RowNum(-1), | ||
}, | ||
{ | ||
name: "ZeroRowNumber", | ||
startWith: models.RowNum(0), | ||
}, | ||
{ | ||
name: "PositiveRowNumber", | ||
startWith: models.RowNum(1), | ||
}, | ||
} | ||
|
||
mockDb, mock, err := sqlmock.New() | ||
if err != nil { | ||
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) | ||
} | ||
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", | ||
}) | ||
db, _ := gorm.Open(dialector, &gorm.Config{}) | ||
|
||
repo := NewRunRepository(db) | ||
|
||
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") | ||
} else { | ||
lockExpect() | ||
err := repo.renumberRows(db, tc.startWith) | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters