From 27aa51687ea5d271b2fa68ea61bc52b7cfb09dd5 Mon Sep 17 00:00:00 2001 From: Barrett Clark Date: Wed, 17 Nov 2021 11:53:20 -0600 Subject: [PATCH] Fix cloud e2e tests for updated migration flow --- ...igrate_state_remote_backend_to_tfc_test.go | 41 +++++++++------ .../e2e/migrate_state_single_to_tfc_test.go | 13 +++-- .../e2e/migrate_state_tfc_to_tfc_test.go | 51 +++++++------------ 3 files changed, 52 insertions(+), 53 deletions(-) diff --git a/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go b/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go index 8da4e0f6e5..19d98ee630 100644 --- a/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_remote_backend_to_tfc_test.go @@ -29,8 +29,8 @@ func Test_migrate_remote_backend_name_to_tfc_name(t *testing.T) { expectedCmdOutput: `Successfully configured the backend "remote"!`, }, { - command: []string{"apply", "-auto-approve"}, - postInputOutput: []string{`Apply complete!`}, + command: []string{"apply", "-auto-approve"}, + expectedCmdOutput: `Apply complete!`, }, }, }, @@ -43,9 +43,11 @@ func Test_migrate_remote_backend_name_to_tfc_name(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Should Terraform migrate your existing state?`, - userInput: []string{"yes"}, - postInputOutput: []string{`Terraform Cloud has been successfully initialized!`}, + expectedCmdOutput: `Migrating from backend "remote" to Terraform Cloud.`, + userInput: []string{"yes", "yes"}, + postInputOutput: []string{ + `Should Terraform migrate your existing state?`, + `Terraform Cloud has been successfully initialized!`}, }, { command: []string{"workspace", "show"}, @@ -164,7 +166,11 @@ func Test_migrate_remote_backend_name_to_tfc_same_name(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Terraform Cloud has been successfully initialized!`, + expectedCmdOutput: `Migrating from backend "remote" to Terraform Cloud.`, + userInput: []string{"yes", "yes"}, + postInputOutput: []string{ + `Should Terraform migrate your existing state?`, + `Terraform Cloud has been successfully initialized!`}, }, { command: []string{"workspace", "show"}, @@ -284,9 +290,11 @@ func Test_migrate_remote_backend_name_to_tfc_name_different_org(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Should Terraform migrate your existing state?`, - userInput: []string{"yes"}, - postInputOutput: []string{`Terraform Cloud has been successfully initialized!`}, + expectedCmdOutput: `Migrating from backend "remote" to Terraform Cloud.`, + userInput: []string{"yes", "yes"}, + postInputOutput: []string{ + `Should Terraform migrate your existing state?`, + `Terraform Cloud has been successfully initialized!`}, }, { command: []string{"workspace", "show"}, @@ -415,10 +423,11 @@ func Test_migrate_remote_backend_name_to_tfc_tags(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`, - userInput: []string{"cloud-workspace", "yes"}, + expectedCmdOutput: `Migrating from backend "remote" to Terraform Cloud.`, + userInput: []string{"yes", "cloud-workspace", "yes"}, postInputOutput: []string{ `Should Terraform migrate your existing state?`, + `Terraform Cloud requires all workspaces to be given an explicit name.`, `Terraform Cloud has been successfully initialized!`}, }, { @@ -545,9 +554,10 @@ func Test_migrate_remote_backend_prefix_to_tfc_name_strategy_single_workspace(t commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Should Terraform migrate your existing state?`, - userInput: []string{"yes"}, + expectedCmdOutput: `Migrating from backend "remote" to Terraform Cloud.`, + userInput: []string{"yes", "yes"}, postInputOutput: []string{ + `Should Terraform migrate your existing state?`, `Terraform Cloud has been successfully initialized!`}, }, { @@ -823,10 +833,11 @@ func Test_migrate_remote_backend_prefix_to_tfc_tags_strategy_single_workspace(t commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`, - userInput: []string{"cloud-workspace", "yes"}, + expectedCmdOutput: `Migrating from backend "remote" to Terraform Cloud.`, + userInput: []string{"yes", "cloud-workspace", "yes"}, postInputOutput: []string{ `Should Terraform migrate your existing state?`, + `Terraform Cloud requires all workspaces to be given an explicit name.`, `Terraform Cloud has been successfully initialized!`}, }, { diff --git a/internal/cloud/e2e/migrate_state_single_to_tfc_test.go b/internal/cloud/e2e/migrate_state_single_to_tfc_test.go index 5bcf9c6697..4865a780d5 100644 --- a/internal/cloud/e2e/migrate_state_single_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_single_to_tfc_test.go @@ -48,9 +48,11 @@ func Test_migrate_single_to_tfc(t *testing.T) { commands: []tfCommand{ { command: []string{"init"}, - expectedCmdOutput: `Should Terraform migrate your existing state?`, - userInput: []string{"yes"}, - postInputOutput: []string{`Terraform Cloud has been successfully initialized!`}, + expectedCmdOutput: `Migrating from backend "local" to Terraform Cloud.`, + userInput: []string{"yes", "yes"}, + postInputOutput: []string{ + `Should Terraform migrate your existing state?`, + `Terraform Cloud has been successfully initialized!`}, }, { command: []string{"workspace", "list"}, @@ -97,10 +99,11 @@ func Test_migrate_single_to_tfc(t *testing.T) { commands: []tfCommand{ { command: []string{"init"}, - expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`, - userInput: []string{"new-workspace", "yes"}, + expectedCmdOutput: `Migrating from backend "local" to Terraform Cloud.`, + userInput: []string{"yes", "new-workspace", "yes"}, postInputOutput: []string{ `Should Terraform migrate your existing state?`, + `Terraform Cloud requires all workspaces to be given an explicit name.`, `Terraform Cloud has been successfully initialized!`}, }, { diff --git a/internal/cloud/e2e/migrate_state_tfc_to_tfc_test.go b/internal/cloud/e2e/migrate_state_tfc_to_tfc_test.go index 125c58d06d..f12dca4186 100644 --- a/internal/cloud/e2e/migrate_state_tfc_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_tfc_to_tfc_test.go @@ -69,10 +69,8 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) { }, commands: []tfCommand{ { - command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Should Terraform migrate your existing state?`, - userInput: []string{"yes"}, - postInputOutput: []string{`Terraform Cloud has been successfully initialized!`}, + command: []string{"init", "-ignore-remote-version"}, + postInputOutput: []string{`Terraform Cloud has been successfully initialized!`}, }, { command: []string{"workspace", "show"}, @@ -128,10 +126,10 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`, - userInput: []string{"new-workspace", "yes"}, + expectedCmdOutput: `There are no workspaces with the configured tags (app)`, + userInput: []string{"new-workspace"}, postInputOutput: []string{ - `Should Terraform migrate your existing state?`, + `Terraform can create a properly tagged workspace for you now.`, `Terraform Cloud has been successfully initialized!`}, }, { @@ -197,9 +195,11 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) { commands: []tfCommand{ { command: []string{"init"}, - expectedCmdOutput: `Terraform Cloud requires all workspaces to be given an explicit name.`, - expectError: true, - userInput: []string{"new-workspace", "yes"}, + expectedCmdOutput: `There are no workspaces with the configured tags (app)`, + userInput: []string{"new-workspace"}, + postInputOutput: []string{ + `Terraform can create a properly tagged workspace for you now.`, + `Terraform Cloud has been successfully initialized!`}, }, }, }, @@ -341,10 +341,8 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) { expectedCmdOutput: `Switched to workspace "app-staging".`, }, { - command: []string{"apply"}, - expectedCmdOutput: `Do you want to perform these actions in workspace "app-staging"?`, - userInput: []string{"yes"}, - postInputOutput: []string{`Apply complete!`}, + command: []string{"apply", "-auto-approve"}, + postInputOutput: []string{`Apply complete!`}, }, { command: []string{"output"}, @@ -368,20 +366,13 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Do you want to copy only your current workspace?`, - userInput: []string{"yes", "yes"}, - postInputOutput: []string{ - `Should Terraform migrate your existing state?`, - `Terraform Cloud has been successfully initialized!`}, + expectedCmdOutput: `Terraform Cloud has been successfully initialized!`, + postInputOutput: []string{`tag_val = "service"`}, }, { command: []string{"workspace", "show"}, expectedCmdOutput: `service`, // this comes from the `prep` function }, - { - command: []string{"output"}, - expectedCmdOutput: `tag_val = "app"`, - }, }, }, }, @@ -447,11 +438,9 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) { commands: []tfCommand{ { command: []string{"init", "-ignore-remote-version"}, - expectedCmdOutput: `Would you like to rename your workspaces?`, - userInput: []string{"1", "new-*", "1"}, - postInputOutput: []string{ - `How would you like to rename your workspaces?`, - `Terraform Cloud has been successfully initialized!`}, + expectedCmdOutput: `There are no workspaces with the configured tags (billing)`, + userInput: []string{"new-app-prod"}, + postInputOutput: []string{`Terraform Cloud has been successfully initialized!`}, }, }, }, @@ -463,17 +452,13 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) { if err != nil { t.Fatal(err) } - if len(wsList.Items) != 2 { + if len(wsList.Items) != 1 { t.Logf("Expected the number of workspaces to be 2, but got %d", len(wsList.Items)) } _, empty := getWorkspace(wsList.Items, "new-app-prod") if empty { t.Fatalf("expected workspaces to include 'new-app-prod' but didn't.") } - _, empty = getWorkspace(wsList.Items, "new-app-staging") - if empty { - t.Fatalf("expected workspaces to include 'new-app-staging' but didn't.") - } }, }, }