From 0e1ce106ab3e2c46a8de974b4d0539f356b1bf07 Mon Sep 17 00:00:00 2001 From: Honnix Date: Wed, 2 Dec 2020 08:50:02 +0100 Subject: [PATCH] Be more generous validating update project (#145) * Be more generous validating update project --- flyteadmin/pkg/manager/impl/project_manager_test.go | 9 +++++---- .../pkg/manager/impl/validation/project_validator.go | 9 +++++---- .../manager/impl/validation/project_validator_test.go | 8 +------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/flyteadmin/pkg/manager/impl/project_manager_test.go b/flyteadmin/pkg/manager/impl/project_manager_test.go index c25307f81..2d9200fd6 100644 --- a/flyteadmin/pkg/manager/impl/project_manager_test.go +++ b/flyteadmin/pkg/manager/impl/project_manager_test.go @@ -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" @@ -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, @@ -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) @@ -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") } diff --git a/flyteadmin/pkg/manager/impl/validation/project_validator.go b/flyteadmin/pkg/manager/impl/validation/project_validator.go index 212113240..5cd60934c 100644 --- a/flyteadmin/pkg/manager/impl/validation/project_validator.go +++ b/flyteadmin/pkg/manager/impl/validation/project_validator.go @@ -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 { @@ -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 } diff --git a/flyteadmin/pkg/manager/impl/validation/project_validator_test.go b/flyteadmin/pkg/manager/impl/validation/project_validator_test.go index 3be5933a7..e6c00a258 100644 --- a/flyteadmin/pkg/manager/impl/validation/project_validator_test.go +++ b/flyteadmin/pkg/manager/impl/validation/project_validator_test.go @@ -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", @@ -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",