Skip to content

Commit

Permalink
Reset Terraform ExecPath on unit tests
Browse files Browse the repository at this point in the history
At the time of acceptance testing, TFMIGRATE_EXEC_PATH was set; this
caused some unit tests to fail where this was not expected. Most tests
for subcommands have no interest in ExecPath, so override it again with
the default value.
  • Loading branch information
minamijoyo committed Nov 16, 2023
1 parent 6f1cd7b commit e589345
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions tfexec/terraform_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestTerraformCLIApply(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
err := terraformCLI.Apply(context.Background(), tc.plan, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestTerraformCLIDestroy(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
err := terraformCLI.Destroy(context.Background(), tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func TestTerraformCLIImport(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.Import(context.Background(), tc.state, tc.address, tc.id, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestTerraformCLIInit(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
err := terraformCLI.Init(context.Background(), tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestTerraformCLIPlan(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.Plan(context.Background(), tc.state, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestTerraformCLIProviders(t *testing.T) {
tc.mockCommands[0].args = []string{"terraform", "providers"}
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.Providers(context.Background())
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_state_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ null_resource.foo
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.StateList(context.Background(), tc.state, tc.addresses, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_state_mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func TestTerraformCLIStateMv(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
gotState, gotStateOut, err := terraformCLI.StateMv(context.Background(), tc.state, tc.stateOut, tc.source, tc.destination, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_state_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestTerraformCLIStatePull(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.StatePull(context.Background(), tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_state_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func TestTerraformCLIStatePush(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
err := terraformCLI.StatePush(context.Background(), tc.state, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_state_replace_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func TestTerraformCLIStateReplaceProvider(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
gotState, err := terraformCLI.StateReplaceProvider(context.Background(), tc.state, tc.source, tc.destination, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_state_rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestTerraformCLIStateRm(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.StateRm(context.Background(), tc.state, tc.addresses, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_workspace_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestTerraformCLIWorkspaceNew(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
err := terraformCLI.WorkspaceNew(context.Background(), tc.workspace, tc.opts...)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_workspace_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestTerraformCLIWorkspaceSelect(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
err := terraformCLI.WorkspaceSelect(context.Background(), tc.workspace)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down
1 change: 1 addition & 0 deletions tfexec/terraform_workspace_show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestTerraformCLIWorkspaceShow(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
e := NewMockExecutor(tc.mockCommands)
terraformCLI := NewTerraformCLI(e)
terraformCLI.SetExecPath("terraform")
got, err := terraformCLI.WorkspaceShow(context.Background())
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
Expand Down

0 comments on commit e589345

Please sign in to comment.