diff --git a/cmd/config/subcommand/project/project_config.go b/cmd/config/subcommand/project/project_config.go index 8fa34ff6..a6e8fceb 100644 --- a/cmd/config/subcommand/project/project_config.go +++ b/cmd/config/subcommand/project/project_config.go @@ -68,6 +68,11 @@ func (c *ConfigProject) GetProjectSpec(id string) (*admin.Project, error) { projectSpec.Labels = &admin.Labels{ Values: c.Labels, } + projectState, err := c.MapToAdminState() + if err != nil { + return nil, err + } + projectSpec.State = projectState return &projectSpec, nil } diff --git a/cmd/update/project.go b/cmd/update/project.go index 0da542b7..7f8b2589 100644 --- a/cmd/update/project.go +++ b/cmd/update/project.go @@ -92,11 +92,6 @@ func updateProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.Comma return fmt.Errorf(clierrors.ErrProjectNotPassed) } - state, err := project.DefaultProjectConfig.MapToAdminState() - if err != nil { - return err - } - projectSpec.State = state if project.DefaultProjectConfig.DryRun { logger.Infof(ctx, "skipping UpdateProject request (dryRun)") } else { diff --git a/cmd/update/project_test.go b/cmd/update/project_test.go index d33ce6e3..b3838b59 100644 --- a/cmd/update/project_test.go +++ b/cmd/update/project_test.go @@ -27,9 +27,11 @@ func updateProjectSetup() { } } -func modifyProjectFlags(archiveProject *bool, newArchiveVal bool, activateProject *bool, newActivateVal bool) { - *archiveProject = newArchiveVal - *activateProject = newActivateVal +func modifyProjectFlags(newArchiveVal bool, newActivateVal bool) { + project.DefaultProjectConfig.ArchiveProject = newArchiveVal + project.DefaultProjectConfig.Archive = newArchiveVal + project.DefaultProjectConfig.ActivateProject = newActivateVal + project.DefaultProjectConfig.Activate = newActivateVal } func TestActivateProjectFunc(t *testing.T) { @@ -37,7 +39,7 @@ func TestActivateProjectFunc(t *testing.T) { updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig.Name = projectValue - modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true) + modifyProjectFlags(false, true) projectUpdateRequest = &admin.Project{ Id: projectValue, Name: projectValue, @@ -58,7 +60,7 @@ func TestActivateProjectFuncWithError(t *testing.T) { updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig.Name = projectValue - modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true) + modifyProjectFlags(false, true) projectUpdateRequest = &admin.Project{ Id: projectValue, Name: projectValue, @@ -80,7 +82,7 @@ func TestArchiveProjectFunc(t *testing.T) { config.GetConfig().Project = projectValue project.DefaultProjectConfig = &project.ConfigProject{} project.DefaultProjectConfig.Name = projectValue - modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), false) + modifyProjectFlags(true, false) projectUpdateRequest = &admin.Project{ Id: projectValue, Name: projectValue, @@ -101,7 +103,7 @@ func TestArchiveProjectFuncWithError(t *testing.T) { updateProjectSetup() project.DefaultProjectConfig.Name = projectValue project.DefaultProjectConfig.Labels = map[string]string{} - modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), false) + modifyProjectFlags(true, false) projectUpdateRequest = &admin.Project{ Id: projectValue, Name: projectValue, @@ -122,7 +124,7 @@ func TestEmptyProjectInput(t *testing.T) { s := setup() updateProjectSetup() config.GetConfig().Project = "" - modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true) + modifyProjectFlags(false, true) err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf(clierrors.ErrProjectNotPassed), err) @@ -133,7 +135,7 @@ func TestInvalidInput(t *testing.T) { updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig.Name = projectValue - modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), true) + modifyProjectFlags(true, true) err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf(clierrors.ErrInvalidStateUpdate), err)