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

Commit

Permalink
Be more generous validating update project (#145)
Browse files Browse the repository at this point in the history
* Be more generous validating update project
  • Loading branch information
honnix authored Dec 2, 2020
1 parent 2d401ac commit 0e1ce10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
9 changes: 5 additions & 4 deletions flyteadmin/pkg/manager/impl/project_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/lyft/flyteadmin/pkg/common"
"github.com/lyft/flyteadmin/pkg/manager/impl/shared"

"github.com/lyft/flyteadmin/pkg/manager/impl/testutils"
"github.com/lyft/flyteadmin/pkg/repositories/interfaces"
Expand Down Expand Up @@ -209,6 +208,7 @@ func TestProjectManager_UpdateProject(t *testing.T) {
assert.Equal(t, "project-id", projectUpdate.Identifier)
assert.Equal(t, "new-project-name", projectUpdate.Name)
assert.Equal(t, "new-project-description", projectUpdate.Description)
assert.Equal(t, int32(admin.Project_ACTIVE), *projectUpdate.State)
return nil
}
projectManager := NewProjectManager(mockRepository,
Expand All @@ -218,6 +218,7 @@ func TestProjectManager_UpdateProject(t *testing.T) {
Id: "project-id",
Name: "new-project-name",
Description: "new-project-description",
State: admin.Project_ACTIVE,
})
assert.Nil(t, err)
assert.True(t, updateFuncCalled)
Expand Down Expand Up @@ -260,8 +261,8 @@ func TestProjectManager_UpdateProject_ErrorDueToInvalidProjectName(t *testing.T)
runtimeMocks.NewMockConfigurationProvider(
getMockApplicationConfigForProjectManagerTest(), nil, nil, nil, nil, nil))
_, err := projectManager.UpdateProject(context.Background(), admin.Project{
Id: "project-id",
// No project name
Id: "project-id",
Name: "longnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamel",
})
assert.Equal(t, shared.GetMissingArgumentError("project_name"), err)
assert.EqualError(t, err, "project_name cannot exceed 64 characters")
}
9 changes: 5 additions & 4 deletions flyteadmin/pkg/manager/impl/validation/project_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ func ValidateProjectRegisterRequest(request admin.ProjectRegisterRequest) error
if request.Project == nil {
return shared.GetMissingArgumentError(shared.Project)
}
return ValidateProject(*request.Project)
project := *request.Project
if err := ValidateEmptyStringField(project.Name, projectName); err != nil {
return err
}
return ValidateProject(project)
}

func ValidateProject(project admin.Project) error {
Expand All @@ -38,9 +42,6 @@ func ValidateProject(project admin.Project) error {
if errs := validation.IsDNS1123Label(project.Id); len(errs) > 0 {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument, "invalid project id [%s]: %v", project.Id, errs)
}
if err := ValidateEmptyStringField(project.Name, projectName); err != nil {
return err
}
if err := ValidateMaxLengthStringField(project.Name, projectName, maxNameLength); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func TestValidateProjectRegisterRequest(t *testing.T) {
func TestValidateProject_ValidProject(t *testing.T) {
assert.Nil(t, ValidateProject(admin.Project{
Id: "proj",
Name: "proj",
Description: "An amazing description for this project",
State: admin.Project_ARCHIVED,
Labels: &admin.Labels{
Values: map[string]string{
"foo": "bar",
Expand Down Expand Up @@ -182,12 +182,6 @@ func TestValidateProject(t *testing.T) {
"characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or " +
"'123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]",
},
{
project: admin.Project{
Id: "proj",
},
expectedError: "missing project_name",
},
{
project: admin.Project{
Id: "proj",
Expand Down

0 comments on commit 0e1ce10

Please sign in to comment.