Skip to content

Commit

Permalink
fix(test): remove tests related to empty task version
Browse files Browse the repository at this point in the history
Signed-off-by: featherchen <[email protected]>
  • Loading branch information
featherchen committed Oct 22, 2024
1 parent 2d88b0d commit 0c20a26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,6 @@ func TestValidateTaskExecutionRequest_MissingFields(t *testing.T) {
}, maxOutputSizeInBytes)
assert.EqualError(t, err, "missing occurred_at")

err = ValidateTaskExecutionRequest(&admin.TaskExecutionEventRequest{
Event: &event.TaskExecutionEvent{
OccurredAt: taskEventOccurredAtProto,
TaskId: &core.Identifier{
ResourceType: core.ResourceType_TASK,
Project: "project",
Domain: "domain",
Name: "name",
},
ParentNodeExecutionId: &core.NodeExecutionIdentifier{
NodeId: "nodey",
ExecutionId: &core.WorkflowExecutionIdentifier{
Project: "project",
Domain: "domain",
Name: "name",
},
},
RetryAttempt: 0,
},
}, maxOutputSizeInBytes)
assert.EqualError(t, err, "missing version")

err = ValidateTaskExecutionRequest(&admin.TaskExecutionEventRequest{
Event: &event.TaskExecutionEvent{
OccurredAt: taskEventOccurredAtProto,
Expand Down
8 changes: 0 additions & 8 deletions flyteadmin/pkg/manager/impl/validation/task_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ func TestValidateTaskEmptyName(t *testing.T) {
assert.EqualError(t, err, "missing name")
}

func TestValidateTaskEmptyVersion(t *testing.T) {
request := testutils.GetValidTaskRequest()
request.Id.Version = ""
err := ValidateTask(context.Background(), request, testutils.GetRepoWithDefaultProject(),
getMockTaskResources(), mockWhitelistConfigProvider, taskApplicationConfigProvider)
assert.EqualError(t, err, "missing version")
}

func TestValidateTaskEmptyType(t *testing.T) {
request := testutils.GetValidTaskRequest()
request.Spec.Template.Type = ""
Expand Down
24 changes: 13 additions & 11 deletions flyteadmin/pkg/repositories/gormimpl/task_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ func (r *TaskRepo) Create(ctx context.Context, input models.Task, descriptionEnt
func (r *TaskRepo) Get(ctx context.Context, input interfaces.Identifier) (models.Task, error) {
var task models.Task
timer := r.metrics.GetDuration.Start()
query := r.db.WithContext(ctx).Where(&models.Task{
TaskKey: models.TaskKey{
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
},
})

var tx *gorm.DB
if input.Version == "" {
query = query.Order("version DESC").Limit(1)
tx := r.db.WithContext(ctx).Limit(1)
tx = tx.Order("DESC")
tx.Find(&task)
} else {
query = query.Where("version = ?", input.Version)
tx = r.db.WithContext(ctx).Where(&models.Task{
TaskKey: models.TaskKey{
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
Version: input.Version,
},
}).Take(&task)
}
tx := query.Take(&task)

timer.Stop()
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return models.Task{}, flyteAdminDbErrors.GetMissingEntityError(core.ResourceType_TASK.String(), &core.Identifier{
Expand Down

0 comments on commit 0c20a26

Please sign in to comment.