From 57a4b51e87686f70f967c28661c23d03f24af12c Mon Sep 17 00:00:00 2001 From: Omar Ismail Date: Thu, 11 Nov 2021 15:21:21 -0500 Subject: [PATCH] remove build tags for cloud e2e --- internal/cloud/e2e/README.md | 3 +-- internal/cloud/e2e/apply_auto_approve_test.go | 3 --- .../cloud/e2e/backend_apply_before_init_test.go | 3 --- internal/cloud/e2e/helper_test.go | 8 ++------ internal/cloud/e2e/init_with_empty_tags_test.go | 3 --- internal/cloud/e2e/main_test.go | 16 +++++++++++----- .../cloud/e2e/migrate_state_multi_to_tfc_test.go | 4 ---- .../migrate_state_remote_backend_to_tfc_test.go | 9 +++------ .../e2e/migrate_state_single_to_tfc_test.go | 3 --- .../cloud/e2e/migrate_state_tfc_to_other_test.go | 3 --- .../cloud/e2e/migrate_state_tfc_to_tfc_test.go | 3 --- internal/cloud/e2e/run_variables_test.go | 9 ++++++--- 12 files changed, 23 insertions(+), 44 deletions(-) diff --git a/internal/cloud/e2e/README.md b/internal/cloud/e2e/README.md index 02a50bbfee..7928fc3f78 100644 --- a/internal/cloud/e2e/README.md +++ b/internal/cloud/e2e/README.md @@ -2,11 +2,10 @@ To run them, use: ``` -TF_ACC=1 go test -tags=e2e ./internal/cloud/e2e/... -ldflags "-X \"github.com/hashicorp/terraform/version.Prerelease=\"" +TFE_TOKEN= TFE_HOSTNAME= TF_ACC=1 go test ./internal/cloud/e2e/... -ldflags "-X \"github.com/hashicorp/terraform/version.Prerelease=\"" ``` Required flags -* `-tags=e2e` for running e2e tests. * `TF_ACC=1`. This variable is used as part of terraform for tests that make external network calls. This is needed to run these tests. Without it, the tests do not run. diff --git a/internal/cloud/e2e/apply_auto_approve_test.go b/internal/cloud/e2e/apply_auto_approve_test.go index 1689caedb3..41bbb11782 100644 --- a/internal/cloud/e2e/apply_auto_approve_test.go +++ b/internal/cloud/e2e/apply_auto_approve_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( diff --git a/internal/cloud/e2e/backend_apply_before_init_test.go b/internal/cloud/e2e/backend_apply_before_init_test.go index 48d3f3d40b..4115ecfab4 100644 --- a/internal/cloud/e2e/backend_apply_before_init_test.go +++ b/internal/cloud/e2e/backend_apply_before_init_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( diff --git a/internal/cloud/e2e/helper_test.go b/internal/cloud/e2e/helper_test.go index 87ed67654e..6c65ba983b 100644 --- a/internal/cloud/e2e/helper_test.go +++ b/internal/cloud/e2e/helper_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( @@ -24,7 +21,6 @@ const ( type tfCommand struct { command []string expectedCmdOutput string - expectedErr string expectError bool userInput []string postInputOutput []string @@ -105,7 +101,7 @@ func randomString(t *testing.T) string { } func terraformConfigLocalBackend() string { - return fmt.Sprintf(` + return ` terraform { backend "local" { } @@ -114,7 +110,7 @@ terraform { output "val" { value = "${terraform.workspace}" } -`) +` } func terraformConfigRemoteBackendName(org, name string) string { diff --git a/internal/cloud/e2e/init_with_empty_tags_test.go b/internal/cloud/e2e/init_with_empty_tags_test.go index 15bc3ba18f..ab74ef9d01 100644 --- a/internal/cloud/e2e/init_with_empty_tags_test.go +++ b/internal/cloud/e2e/init_with_empty_tags_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( diff --git a/internal/cloud/e2e/main_test.go b/internal/cloud/e2e/main_test.go index 783dc4d201..656c093fac 100644 --- a/internal/cloud/e2e/main_test.go +++ b/internal/cloud/e2e/main_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( @@ -27,8 +24,9 @@ var verboseMode bool func TestMain(m *testing.M) { log.SetFlags(log.LstdFlags | log.Lshortfile) - if !accTest() { - // if TF_ACC is not set, we want to skip all these tests. + hasRequiredEnvVars := accTest() && hasHostname() && hasToken() + if !hasRequiredEnvVars { + // if the above three required variables are not set, then skip all tests. return } teardown := setup() @@ -44,6 +42,14 @@ func accTest() bool { return os.Getenv("TF_ACC") != "" } +func hasHostname() bool { + return os.Getenv("TFE_HOSTNAME") != "" +} + +func hasToken() bool { + return os.Getenv("TFE_TOKEN") != "" +} + func setup() func() { tfOutput := flag.Bool("tfoutput", false, "This flag produces the terraform output from tests.") flag.Parse() diff --git a/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go b/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go index 07c4b04f88..7e1ff542b7 100644 --- a/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_multi_to_tfc_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( @@ -186,7 +183,6 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) { for _, op := range tc.operations { op.prep(t, organization.Name, tf.WorkDir()) for _, tfCmd := range op.commands { - tfCmd.command = append(tfCmd.command) cmd := tf.Cmd(tfCmd.command...) cmd.Stdin = exp.Tty() cmd.Stdout = exp.Tty() 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 819875e3f1..b502281921 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 @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( @@ -705,15 +702,15 @@ func Test_migrate_remote_backend_prefix_to_tfc_name_strategy_multi_workspace(t * if len(wsList.Items) != 3 { t.Fatalf("expected number of workspaces in this org to be 3, but got %d", len(wsList.Items)) } - ws, empty := getWorkspace(wsList.Items, "cloud-workspace") + _, empty := getWorkspace(wsList.Items, "cloud-workspace") if empty { t.Fatalf("expected workspaces to include 'cloud-workspace' but didn't.") } - ws, empty = getWorkspace(wsList.Items, "app-one") + _, empty = getWorkspace(wsList.Items, "app-one") if empty { t.Fatalf("expected workspaces to include 'app-one' but didn't.") } - ws, empty = getWorkspace(wsList.Items, "app-two") + _, empty = getWorkspace(wsList.Items, "app-two") if empty { t.Fatalf("expected workspaces to include 'app-two' but didn't.") } 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 14c84eef9e..e171f048a6 100644 --- a/internal/cloud/e2e/migrate_state_single_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_single_to_tfc_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( diff --git a/internal/cloud/e2e/migrate_state_tfc_to_other_test.go b/internal/cloud/e2e/migrate_state_tfc_to_other_test.go index 6e8b3a9019..3da776c3f1 100644 --- a/internal/cloud/e2e/migrate_state_tfc_to_other_test.go +++ b/internal/cloud/e2e/migrate_state_tfc_to_other_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( 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 496bf98810..64204565dc 100644 --- a/internal/cloud/e2e/migrate_state_tfc_to_tfc_test.go +++ b/internal/cloud/e2e/migrate_state_tfc_to_tfc_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( diff --git a/internal/cloud/e2e/run_variables_test.go b/internal/cloud/e2e/run_variables_test.go index 5f4f40cec8..b4d3569a2a 100644 --- a/internal/cloud/e2e/run_variables_test.go +++ b/internal/cloud/e2e/run_variables_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package main import ( @@ -10,7 +7,9 @@ import ( "testing" expect "github.com/Netflix/go-expect" + tfe "github.com/hashicorp/go-tfe" "github.com/hashicorp/terraform/internal/e2e" + tfversion "github.com/hashicorp/terraform/version" ) func terraformConfigRequiredVariable(org, name string) string { @@ -54,6 +53,10 @@ func Test_cloud_run_variables(t *testing.T) { { prep: func(t *testing.T, orgName, dir string) { wsName := "new-workspace" + _ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{ + Name: tfe.String(wsName), + TerraformVersion: tfe.String(tfversion.String()), + }) tfBlock := terraformConfigRequiredVariable(orgName, wsName) writeMainTF(t, tfBlock, dir) },