Skip to content

Commit

Permalink
Use ... to keep testcase codes
Browse files Browse the repository at this point in the history
  • Loading branch information
uchida committed Jul 5, 2022
1 parent 2bfdbe2 commit 1ab353b
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tfexec/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ resource "aws_security_group" "foo" {}
resource "aws_security_group" "bar" {}
`
workspace := "work1"
terraformCLI := SetupTestAccWithApply(t, workspace, backend+source, nil)
terraformCLI := SetupTestAccWithApply(t, workspace, backend+source)

updatedSource := `
resource "aws_security_group" "foo2" {}
Expand Down Expand Up @@ -216,7 +216,7 @@ resource "aws_security_group" "bar" {}
`
workspace := "work1"
backendConfig := []string{"bucket=tfstate-test"}
terraformCLI := SetupTestAccWithApply(t, workspace, backend+source, backendConfig)
terraformCLI := SetupTestAccWithApply(t, workspace, backend+source, backendConfig...)

updatedSource := `
resource "aws_security_group" "foo2" {}
Expand Down
6 changes: 4 additions & 2 deletions tfexec/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,17 @@ provider "aws" {

// SetupTestAccWithApply is an acceptance test helper for initializing a
// temporary work directory and applying a given source.
func SetupTestAccWithApply(t *testing.T, workspace string, source string, backendConfig []string) TerraformCLI {
func SetupTestAccWithApply(t *testing.T, workspace string, source string, backendConfig ...string) TerraformCLI {
t.Helper()

e := SetupTestAcc(t, source)
tf := NewTerraformCLI(e)
ctx := context.Background()

var args = []string{"-input=false", "-no-color"}
args = append(args, backendConfig...)
for _, b := range backendConfig {
args = append(args, fmt.Sprintf("-backend-config=%s", b))
}
err := tf.Init(ctx, args...)
if err != nil {
t.Fatalf("failed to run terraform init: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions tfmigrate/multi_state_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ func TestAccMultiStateMigratorApply(t *testing.T) {

//setup the initial files and states
fromBackend := tfexec.GetTestAccBackendS3Config(t.Name() + "/fromDir")
fromTf := tfexec.SetupTestAccWithApply(t, tc.fromWorkspace, fromBackend+tc.fromSource, nil)
fromTf := tfexec.SetupTestAccWithApply(t, tc.fromWorkspace, fromBackend+tc.fromSource)
toBackend := tfexec.GetTestAccBackendS3Config(t.Name() + "/toDir")
toTf := tfexec.SetupTestAccWithApply(t, tc.toWorkspace, toBackend+tc.toSource, nil)
toTf := tfexec.SetupTestAccWithApply(t, tc.toWorkspace, toBackend+tc.toSource)

//update terraform resource files for migration
tfexec.UpdateTestAccSource(t, fromTf, fromBackend+tc.fromUpdatedSource)
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/state_import_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resource "aws_iam_user" "baz" {
name = "baz"
}
`
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source, nil)
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source)
ctx := context.Background()

_, err := tf.StateRm(ctx, nil, []string{"aws_iam_user.foo", "aws_iam_user.baz"})
Expand Down
4 changes: 2 additions & 2 deletions tfmigrate/state_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ resource "aws_iam_user" "qux" {
name = "qux"
}
`
tf := tfexec.SetupTestAccWithApply(t, tc.workspace, backend+source, nil)
tf := tfexec.SetupTestAccWithApply(t, tc.workspace, backend+source)
ctx := context.Background()

updatedSource := `
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestAccStateMigratorApplyForce(t *testing.T) {
resource "aws_security_group" "foo" {}
resource "aws_security_group" "bar" {}
`
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source, nil)
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source)
ctx := context.Background()

updatedSource := `
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/state_mv_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "aws_security_group" "foo" {}
resource "aws_security_group" "bar" {}
resource "aws_security_group" "baz" {}
`
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source, nil)
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source)
ctx := context.Background()

updatedSource := `
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/state_rm_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_security_group" "bar" {}
resource "aws_security_group" "baz" {}
resource "aws_security_group" "qux" {}
`
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source, nil)
tf := tfexec.SetupTestAccWithApply(t, "default", backend+source)
ctx := context.Background()

updatedSource := `
Expand Down

0 comments on commit 1ab353b

Please sign in to comment.