Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yee Hing Tong <[email protected]>
  • Loading branch information
wild-endeavor committed Oct 2, 2022
1 parent 8848d1e commit 6f0ede5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/repositories/gormimpl/resource_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/repositories/gormimpl/resource_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"testing"

"gorm.io/gorm"

"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"

mocket "github.com/Selvatico/go-mocket"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
17 changes: 17 additions & 0 deletions pkg/repositories/transformers/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 6f0ede5

Please sign in to comment.