From bd6b85605f49ff4877484edd69942ca72f4e19dd Mon Sep 17 00:00:00 2001
From: Katrina Rogan <katroganGH@gmail.com>
Date: Mon, 17 Apr 2023 15:17:10 -0700
Subject: [PATCH] Respect project state in project.yaml file (#402)

---
 .../subcommand/project/project_config.go      |  5 +++++
 cmd/update/project.go                         |  5 -----
 cmd/update/project_test.go                    | 20 ++++++++++---------
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/cmd/config/subcommand/project/project_config.go b/cmd/config/subcommand/project/project_config.go
index 8fa34ff6a5..a6e8fcebd6 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 0da542b763..7f8b2589e9 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 d33ce6e374..b3838b59ac 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)