Skip to content

Commit

Permalink
Moved Validation to it's right place.
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Raposo <[email protected]>
  • Loading branch information
RRap0so committed Mar 19, 2024
1 parent 39a6ccd commit 681d2fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flyteadmin/pkg/manager/impl/project_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func (m *ProjectManager) UpdateProject(ctx context.Context, projectUpdate admin.
}

func (m *ProjectManager) GetProject(ctx context.Context, request admin.ProjectGetRequest) (*admin.Project, error) {
if request.Id == "" {
return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "project identifier is required")
if err := validation.ValidateProjectGetRequest(request); err != nil {
return nil, err
}
projectModel, err := m.db.ProjectRepo().Get(ctx, request.Id)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion flyteadmin/pkg/manager/impl/project_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,5 @@ func TestProjectManager_TestGetProject_ErrorDueToEmptyProjectGetRequest(t *testi
_, err := projectManager.GetProject(context.Background(),
*mockedProject)

assert.EqualError(t, err, "project identifier is required")
assert.EqualError(t, err, "missing project_id")
}
7 changes: 7 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/project_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func ValidateProjectRegisterRequest(request admin.ProjectRegisterRequest) error
return ValidateProject(project)
}

func ValidateProjectGetRequest(request admin.ProjectGetRequest) error {
if err := ValidateEmptyStringField(request.Id, projectID); err != nil {
return err
}
return nil
}

func ValidateProject(project admin.Project) error {
if err := ValidateEmptyStringField(project.Id, projectID); err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/project_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,15 @@ func TestValidateProjectExistsDb(t *testing.T) {
assert.Error(t, err)
})
}

func TestValidateProjectGetRequest(t *testing.T) {
t.Run("base case", func(t *testing.T) {
assert.Nil(t, ValidateProjectGetRequest(admin.ProjectGetRequest{
Id: "project-id",
}))
})

t.Run("missing project id", func(t *testing.T) {
assert.EqualError(t, ValidateProjectGetRequest(admin.ProjectGetRequest{}), "missing project_id")
})
}

0 comments on commit 681d2fb

Please sign in to comment.