Skip to content

Commit 296acdd

Browse files
authored
Merge pull request #30020 from hashicorp/barrettclark/cloud-e2e-parallel
Cloud: Add parallelism back into the tests
2 parents f772cb0 + d196d28 commit 296acdd

11 files changed

+588
-1816
lines changed

internal/cloud/e2e/apply_auto_approve_test.go

+3-79
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@ package main
22

33
import (
44
"context"
5-
"io/ioutil"
6-
"os"
75
"testing"
86

9-
expect "github.com/Netflix/go-expect"
107
tfe "github.com/hashicorp/go-tfe"
11-
"github.com/hashicorp/terraform/internal/e2e"
128
tfversion "github.com/hashicorp/terraform/version"
139
)
1410

1511
func Test_terraform_apply_autoApprove(t *testing.T) {
12+
t.Parallel()
1613
skipIfMissingEnvVar(t)
1714
skipWithoutRemoteTerraformVersion(t)
1815

1916
ctx := context.Background()
2017

21-
cases := map[string]struct {
22-
operations []operationSets
23-
validations func(t *testing.T, orgName string)
24-
}{
18+
cases := testCases{
2519
"workspace manual apply, terraform apply without auto-approve, expect prompt": {
2620
operations: []operationSets{
2721
{
@@ -179,76 +173,6 @@ func Test_terraform_apply_autoApprove(t *testing.T) {
179173
},
180174
},
181175
}
182-
for name, tc := range cases {
183-
tc := tc
184-
t.Run(name, func(t *testing.T) {
185-
// t.Parallel()
186-
organization, cleanup := createOrganization(t)
187-
defer cleanup()
188-
exp, err := expect.NewConsole(defaultOpts()...)
189-
if err != nil {
190-
t.Fatal(err)
191-
}
192-
defer exp.Close()
193176

194-
tmpDir, err := ioutil.TempDir("", "terraform-test")
195-
if err != nil {
196-
t.Fatal(err)
197-
}
198-
defer os.RemoveAll(tmpDir)
199-
200-
tf := e2e.NewBinary(terraformBin, tmpDir)
201-
tf.AddEnv(cliConfigFileEnv)
202-
defer tf.Close()
203-
204-
for _, op := range tc.operations {
205-
op.prep(t, organization.Name, tf.WorkDir())
206-
for _, tfCmd := range op.commands {
207-
cmd := tf.Cmd(tfCmd.command...)
208-
cmd.Stdin = exp.Tty()
209-
cmd.Stdout = exp.Tty()
210-
cmd.Stderr = exp.Tty()
211-
212-
err = cmd.Start()
213-
if err != nil {
214-
t.Fatal(err)
215-
}
216-
217-
if tfCmd.expectedCmdOutput != "" {
218-
got, err := exp.ExpectString(tfCmd.expectedCmdOutput)
219-
if err != nil {
220-
t.Fatalf("error while waiting for output\nwant: %s\nerror: %s\noutput\n%s", tfCmd.expectedCmdOutput, err, got)
221-
}
222-
}
223-
224-
lenInput := len(tfCmd.userInput)
225-
lenInputOutput := len(tfCmd.postInputOutput)
226-
if lenInput > 0 {
227-
for i := 0; i < lenInput; i++ {
228-
input := tfCmd.userInput[i]
229-
exp.SendLine(input)
230-
// use the index to find the corresponding
231-
// output that matches the input.
232-
if lenInputOutput-1 >= i {
233-
output := tfCmd.postInputOutput[i]
234-
_, err := exp.ExpectString(output)
235-
if err != nil {
236-
t.Fatal(err)
237-
}
238-
}
239-
}
240-
}
241-
242-
err = cmd.Wait()
243-
if err != nil && !tfCmd.expectError {
244-
t.Fatal(err)
245-
}
246-
}
247-
}
248-
249-
if tc.validations != nil {
250-
tc.validations(t, organization.Name)
251-
}
252-
})
253-
}
177+
testRunner(t, cases, 1)
254178
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
package main
22

33
import (
4-
"io/ioutil"
5-
"os"
64
"testing"
7-
8-
expect "github.com/Netflix/go-expect"
9-
"github.com/hashicorp/terraform/internal/e2e"
105
)
116

127
func Test_backend_apply_before_init(t *testing.T) {
8+
t.Parallel()
139
skipIfMissingEnvVar(t)
14-
// t.Parallel()
1510
skipWithoutRemoteTerraformVersion(t)
1611

17-
cases := map[string]struct {
18-
operations []operationSets
19-
}{
12+
cases := testCases{
2013
"terraform apply with cloud block - blank state": {
2114
operations: []operationSets{
2215
{
@@ -71,72 +64,5 @@ func Test_backend_apply_before_init(t *testing.T) {
7164
},
7265
}
7366

74-
for name, tc := range cases {
75-
tc := tc
76-
t.Run(name, func(t *testing.T) {
77-
// t.Parallel()
78-
organization, cleanup := createOrganization(t)
79-
defer cleanup()
80-
exp, err := expect.NewConsole(defaultOpts()...)
81-
if err != nil {
82-
t.Fatal(err)
83-
}
84-
defer exp.Close()
85-
86-
tmpDir, err := ioutil.TempDir("", "terraform-test")
87-
if err != nil {
88-
t.Fatal(err)
89-
}
90-
defer os.RemoveAll(tmpDir)
91-
92-
tf := e2e.NewBinary(terraformBin, tmpDir)
93-
tf.AddEnv(cliConfigFileEnv)
94-
defer tf.Close()
95-
96-
for _, op := range tc.operations {
97-
op.prep(t, organization.Name, tf.WorkDir())
98-
for _, tfCmd := range op.commands {
99-
cmd := tf.Cmd(tfCmd.command...)
100-
cmd.Stdin = exp.Tty()
101-
cmd.Stdout = exp.Tty()
102-
cmd.Stderr = exp.Tty()
103-
104-
err = cmd.Start()
105-
if err != nil {
106-
t.Fatal(err)
107-
}
108-
109-
if tfCmd.expectedCmdOutput != "" {
110-
got, err := exp.ExpectString(tfCmd.expectedCmdOutput)
111-
if err != nil {
112-
t.Fatalf("error while waiting for output\nwant: %s\nerror: %s\noutput\n%s", tfCmd.expectedCmdOutput, err, got)
113-
}
114-
}
115-
116-
lenInput := len(tfCmd.userInput)
117-
lenInputOutput := len(tfCmd.postInputOutput)
118-
if lenInput > 0 {
119-
for i := 0; i < lenInput; i++ {
120-
input := tfCmd.userInput[i]
121-
exp.SendLine(input)
122-
// use the index to find the corresponding
123-
// output that matches the input.
124-
if lenInputOutput-1 >= i {
125-
output := tfCmd.postInputOutput[i]
126-
_, err := exp.ExpectString(output)
127-
if err != nil {
128-
t.Fatal(err)
129-
}
130-
}
131-
}
132-
}
133-
134-
err = cmd.Wait()
135-
if err != nil && !tfCmd.expectError {
136-
t.Fatal(err)
137-
}
138-
}
139-
}
140-
})
141-
}
67+
testRunner(t, cases, 1)
14268
}

internal/cloud/e2e/helper_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515
)
1616

1717
const (
18-
expectConsoleTimeout = 15 * time.Second
18+
// We need to give the console enough time to hear back.
19+
// 1 minute was too short in some cases, so this gives it ample time.
20+
expectConsoleTimeout = 3 * time.Minute
1921
)
2022

2123
type tfCommand struct {
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
package main
22

33
import (
4-
"io/ioutil"
5-
"os"
64
"testing"
7-
8-
expect "github.com/Netflix/go-expect"
9-
"github.com/hashicorp/terraform/internal/e2e"
105
)
116

127
func Test_init_with_empty_tags(t *testing.T) {
8+
t.Parallel()
139
skipIfMissingEnvVar(t)
14-
// t.Parallel()
1510
skipWithoutRemoteTerraformVersion(t)
1611

17-
cases := map[string]struct {
18-
operations []operationSets
19-
}{
12+
cases := testCases{
2013
"terraform init with cloud block - no tagged workspaces exist yet": {
2114
operations: []operationSets{
2215
{
@@ -38,71 +31,5 @@ func Test_init_with_empty_tags(t *testing.T) {
3831
},
3932
}
4033

41-
for name, tc := range cases {
42-
tc := tc
43-
t.Run(name, func(t *testing.T) {
44-
// t.Parallel()
45-
organization, cleanup := createOrganization(t)
46-
defer cleanup()
47-
exp, err := expect.NewConsole(defaultOpts()...)
48-
if err != nil {
49-
t.Fatal(err)
50-
}
51-
defer exp.Close()
52-
53-
tmpDir, err := ioutil.TempDir("", "terraform-test")
54-
if err != nil {
55-
t.Fatal(err)
56-
}
57-
defer os.RemoveAll(tmpDir)
58-
59-
tf := e2e.NewBinary(terraformBin, tmpDir)
60-
tf.AddEnv(cliConfigFileEnv)
61-
defer tf.Close()
62-
63-
for _, op := range tc.operations {
64-
op.prep(t, organization.Name, tf.WorkDir())
65-
for _, tfCmd := range op.commands {
66-
cmd := tf.Cmd(tfCmd.command...)
67-
cmd.Stdin = exp.Tty()
68-
cmd.Stdout = exp.Tty()
69-
cmd.Stderr = exp.Tty()
70-
71-
err = cmd.Start()
72-
if err != nil {
73-
t.Fatal(err)
74-
}
75-
76-
if tfCmd.expectedCmdOutput != "" {
77-
got, err := exp.ExpectString(tfCmd.expectedCmdOutput)
78-
if err != nil {
79-
t.Fatalf("error while waiting for output\nwant: %s\nerror: %s\noutput\n%s", tfCmd.expectedCmdOutput, err, got)
80-
}
81-
}
82-
83-
lenInput := len(tfCmd.userInput)
84-
lenInputOutput := len(tfCmd.postInputOutput)
85-
if lenInput > 0 {
86-
for i := 0; i < lenInput; i++ {
87-
input := tfCmd.userInput[i]
88-
exp.SendLine(input)
89-
// use the index to find the corresponding
90-
// output that matches the input.
91-
if lenInputOutput-1 >= i {
92-
output := tfCmd.postInputOutput[i]
93-
_, err := exp.ExpectString(output)
94-
if err != nil {
95-
t.Fatal(err)
96-
}
97-
}
98-
}
99-
}
100-
err = cmd.Wait()
101-
if err != nil && !tfCmd.expectError {
102-
t.Fatal(err)
103-
}
104-
}
105-
}
106-
})
107-
}
34+
testRunner(t, cases, 1)
10835
}

0 commit comments

Comments
 (0)