Skip to content

Commit 05039b6

Browse files
authored
acceptance: restructure e2e for deterministic results (#53)
Go maps being unordered strikes again. Restructure the e2e tests so that they are generated using slices instead of maps. Signed-off-by: Ryan Cragun <[email protected]>
1 parent d544766 commit 05039b6

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

acceptance/scenario_e2e_aws_test.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
3131
for _, test := range []struct {
3232
dir string
3333
name string
34-
variants map[string][][]string
34+
variants []struct {
35+
uid string
36+
variants [][]string
37+
}
3538
}{
3639
{
37-
"scenario_e2e_aws",
38-
"e2e",
39-
map[string][][]string{
40-
fmt.Sprintf("%x", sha256.Sum256([]byte("e2e [aws_region:east distro:rhel]"))): {
41-
{"aws_region", "east"}, {"distro", "rhel"},
40+
dir: "scenario_e2e_aws",
41+
name: "e2e",
42+
variants: []struct {
43+
uid string
44+
variants [][]string
45+
}{
46+
{
47+
fmt.Sprintf("%x", sha256.Sum256([]byte("e2e [aws_region:east distro:rhel]"))),
48+
[][]string{{"aws_region", "east"}, {"distro", "rhel"}},
4249
},
43-
fmt.Sprintf("%x", sha256.Sum256([]byte("e2e [aws_region:west distro:ubuntu]"))): {
44-
{"aws_region", "west"}, {"distro", "ubuntu"},
50+
{
51+
fmt.Sprintf("%x", sha256.Sum256([]byte("e2e [aws_region:west distro:ubuntu]"))),
52+
[][]string{{"aws_region", "west"}, {"distro", "ubuntu"}},
4553
},
4654
},
4755
},
@@ -64,19 +72,19 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
6472

6573
// Since we failed lets output something useful that might help
6674
// us debug the problem
67-
for uid := range test.variants {
68-
bytes, err := os.ReadFile(filepath.Join(outDir, uid, "scenario.tf"))
75+
for _, variant := range test.variants {
76+
bytes, err := os.ReadFile(filepath.Join(outDir, variant.uid, "scenario.tf"))
6977
if err != nil {
7078
t.Logf("unable to read failed scenario's generated module: %s", err.Error())
7179
} else {
72-
t.Logf("%s/scenario.tf\n (%s) %s", uid, test.name, string(bytes))
80+
t.Logf("%s/scenario.tf\n (%s) %s", variant.uid, test.name, string(bytes))
7381
}
7482

75-
bytes, err = os.ReadFile(filepath.Join(outDir, uid, "terraform.rc"))
83+
bytes, err = os.ReadFile(filepath.Join(outDir, variant.uid, "terraform.rc"))
7684
if err != nil {
7785
t.Logf("unable to read failed scenario's generated cli config: %s", err.Error())
7886
} else {
79-
t.Logf("%s/terraform.rc (%s)\n %s", uid, test.name, string(bytes))
87+
t.Logf("%s/terraform.rc (%s)\n %s", variant.uid, test.name, string(bytes))
8088
}
8189
}
8290

@@ -89,24 +97,24 @@ func TestAcc_Cmd_Scenario_E2E_AWS(t *testing.T) {
8997
expected := &pb.RunScenariosResponse{
9098
Responses: []*pb.Scenario_Command_Run_Response{},
9199
}
92-
for uid, variants := range test.variants {
100+
for _, variant := range test.variants {
93101
elements := []*pb.Scenario_Filter_Element{}
94-
for _, variant := range variants {
102+
for _, v := range variant.variants {
95103
elements = append(elements, &pb.Scenario_Filter_Element{
96-
Key: variant[0],
97-
Value: variant[1],
104+
Key: v[0],
105+
Value: v[1],
98106
})
99107
}
100108

101109
res := &pb.Scenario_Command_Run_Response{
102110
Generate: &pb.Scenario_Command_Generate_Response{
103111
TerraformModule: &pb.Terraform_Module{
104-
ModulePath: filepath.Join(outDir, uid, "scenario.tf"),
105-
RcPath: filepath.Join(outDir, uid, "terraform.rc"),
112+
ModulePath: filepath.Join(outDir, variant.uid, "scenario.tf"),
113+
RcPath: filepath.Join(outDir, variant.uid, "terraform.rc"),
106114
ScenarioRef: &pb.Ref_Scenario{
107115
Id: &pb.Scenario_ID{
108116
Name: test.name,
109-
Uid: uid,
117+
Uid: variant.uid,
110118
Variants: &pb.Scenario_Filter_Vector{
111119
Elements: elements,
112120
},

0 commit comments

Comments
 (0)