diff --git a/pkg/repositories/gormimpl/resource_repo.go b/pkg/repositories/gormimpl/resource_repo.go index 71aa28bec..1f94abce5 100644 --- a/pkg/repositories/gormimpl/resource_repo.go +++ b/pkg/repositories/gormimpl/resource_repo.go @@ -131,7 +131,6 @@ func (r *ResourceRepo) Get(ctx context.Context, ID interfaces.ResourceID) (model // given ResourceType if it exists. The reason this exists is because we want to return project level // attributes to Flyte Console, regardless of whether a more specific setting exists. func (r *ResourceRepo) GetProjectLevel(ctx context.Context, ID interfaces.ResourceID) (models.Resource, error) { - if ID.Project == "" { return models.Resource{}, r.errorTransformer.ToFlyteAdminError(flyteAdminDbErrors.GetInvalidInputError(fmt.Sprintf("%v", ID))) } diff --git a/pkg/repositories/gormimpl/resource_repo_test.go b/pkg/repositories/gormimpl/resource_repo_test.go index dbd7ca415..1ea145d9d 100644 --- a/pkg/repositories/gormimpl/resource_repo_test.go +++ b/pkg/repositories/gormimpl/resource_repo_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + "gorm.io/gorm" + "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces" mocket "github.com/Selvatico/go-mocket" @@ -153,6 +155,10 @@ func TestProjectLevelAttributes(t *testing.T) { assert.Equal(t, "", output.Workflow) assert.Equal(t, "resource-type", output.ResourceType) assert.Equal(t, []byte("attrs"), output.Attributes) + + // Must have a project defined + _, err = resourceRepo.GetProjectLevel(context.Background(), interfaces.ResourceID{Project: "", Domain: "", ResourceType: "resource"}) + assert.Error(t, err) } func TestGetRawWorkflowAttributes(t *testing.T) { @@ -224,3 +230,18 @@ func TestListAll(t *testing.T) { assert.Equal(t, []byte("attrs"), output[0].Attributes) assert.True(t, fakeResponse.Triggered) } + +func TestGetError(t *testing.T) { + resourceRepo := NewResourceRepo(GetDbForTest(t), errors.NewTestErrorTransformer(), mockScope.NewTestScope()) + GlobalMock := mocket.Catcher.Reset() + GlobalMock.Logging = true + + query := GlobalMock.NewMock() + query.WithQuery(`SELECT * FROM "resources" WHERE resource_type = $1 AND domain IN ($2,$3) AND project IN ($4,$5) AND workflow IN ($6,$7) AND launch_plan IN ($8) ORDER BY priority desc,"resources"."id" LIMIT 1`).WithError(gorm.ErrRecordNotFound) + + output, err := resourceRepo.Get(context.Background(), interfaces.ResourceID{Project: "project", Domain: "domain", Workflow: "workflow", ResourceType: "resource"}) + assert.Error(t, err) + assert.Equal(t, "", output.Project) + assert.Equal(t, "", output.Domain) + assert.Equal(t, "", output.Workflow) +} diff --git a/pkg/repositories/transformers/resource_test.go b/pkg/repositories/transformers/resource_test.go index 23c5a63d1..1a7a32b1b 100644 --- a/pkg/repositories/transformers/resource_test.go +++ b/pkg/repositories/transformers/resource_test.go @@ -250,3 +250,20 @@ func TestFromWorkflowAttributesModel_InvalidResourceAttributes(t *testing.T) { assert.NotNil(t, err) assert.Equal(t, codes.Internal, err.(errors.FlyteAdminError).Code()) } + +func TestProjectAttributesToResourceModel(t *testing.T) { + pa := admin.ProjectAttributes{ + Project: resourceProject, + MatchingAttributes: matchingClusterResourceAttributes, + } + rm, err := ProjectAttributesToResourceModel(pa, admin.MatchableResource_CLUSTER_RESOURCE) + + assert.NoError(t, err) + assert.EqualValues(t, models.Resource{ + Project: resourceProject, + Domain: "", + ResourceType: admin.MatchableResource_CLUSTER_RESOURCE.String(), + Priority: models.ResourcePriorityProjectLevel, + Attributes: marshalledClusterResourceAttributes, + }, rm) +}