Skip to content

Commit

Permalink
feat(test): TestGetTask
Browse files Browse the repository at this point in the history
Signed-off-by: featherchen <[email protected]>
  • Loading branch information
featherchen committed Oct 23, 2024
1 parent 0c20a26 commit 09cd2e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flyteadmin/pkg/repositories/gormimpl/task_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (r *TaskRepo) Get(ctx context.Context, input interfaces.Identifier) (models
timer := r.metrics.GetDuration.Start()
var tx *gorm.DB
if input.Version == "" {
tx := r.db.WithContext(ctx).Limit(1)
tx = tx.Order("DESC")
tx := r.db.WithContext(ctx).Where("project = ? AND domain = ? AND name = ?", input.Project, input.Domain, input.Name).Limit(1)
tx = tx.Order("version DESC")
tx.Find(&task)
} else {
tx = r.db.WithContext(ctx).Where(&models.Task{
Expand Down
22 changes: 22 additions & 0 deletions flyteadmin/pkg/repositories/gormimpl/task_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ func TestGetTask(t *testing.T) {
assert.Equal(t, version, output.Version)
assert.Equal(t, []byte{1, 2}, output.Closure)
assert.Equal(t, pythonTestTaskType, output.Type)

//When version is empty, return the latest task
GlobalMock = mocket.Catcher.Reset()
GlobalMock.Logging = true

GlobalMock.NewMock().WithQuery(
`SELECT * FROM "tasks" WHERE project = $1 AND domain = $2 AND name = $3 ORDER BY version DESC LIMIT 1`).
WithReply(tasks)
output, err = taskRepo.Get(context.Background(), interfaces.Identifier{
Project: project,
Domain: domain,
Name: name,
Version: "",
})

assert.NoError(t, err)
assert.Equal(t, project, output.Project)
assert.Equal(t, domain, output.Domain)
assert.Equal(t, name, output.Name)
assert.Equal(t, "v2", output.Version)
assert.Equal(t, []byte{3, 4}, output.Closure)
assert.Equal(t, pythonTestTaskType, output.Type)
}

func TestListTasks(t *testing.T) {
Expand Down

0 comments on commit 09cd2e3

Please sign in to comment.