-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make junitXMLTestReport output deterministic by iterating over a slic…
…e instead of a map, add test
- Loading branch information
1 parent
2bdb205
commit 4a06b78
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package artifact | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/internal/moduletest" | ||
) | ||
|
||
func Test_suiteFilesAsSortedList(t *testing.T) { | ||
cases := map[string]struct { | ||
Suite *moduletest.Suite | ||
ExpectedNames map[int]string | ||
}{ | ||
"no test files": { | ||
Suite: &moduletest.Suite{}, | ||
}, | ||
"3 test files ordered in map": { | ||
Suite: &moduletest.Suite{ | ||
Status: moduletest.Skip, | ||
Files: map[string]*moduletest.File{ | ||
"test_file_1.tftest.hcl": { | ||
Name: "test_file_1.tftest.hcl", | ||
Status: moduletest.Skip, | ||
Runs: []*moduletest.Run{}, | ||
}, | ||
"test_file_2.tftest.hcl": { | ||
Name: "test_file_2.tftest.hcl", | ||
Status: moduletest.Skip, | ||
Runs: []*moduletest.Run{}, | ||
}, | ||
"test_file_3.tftest.hcl": { | ||
Name: "test_file_3.tftest.hcl", | ||
Status: moduletest.Skip, | ||
Runs: []*moduletest.Run{}, | ||
}, | ||
}, | ||
}, | ||
ExpectedNames: map[int]string{ | ||
0: "test_file_1.tftest.hcl", | ||
1: "test_file_2.tftest.hcl", | ||
2: "test_file_3.tftest.hcl", | ||
}, | ||
}, | ||
"3 test files unordered in map": { | ||
Suite: &moduletest.Suite{ | ||
Status: moduletest.Skip, | ||
Files: map[string]*moduletest.File{ | ||
"test_file_3.tftest.hcl": { | ||
Name: "test_file_3.tftest.hcl", | ||
Status: moduletest.Skip, | ||
Runs: []*moduletest.Run{}, | ||
}, | ||
"test_file_1.tftest.hcl": { | ||
Name: "test_file_1.tftest.hcl", | ||
Status: moduletest.Skip, | ||
Runs: []*moduletest.Run{}, | ||
}, | ||
"test_file_2.tftest.hcl": { | ||
Name: "test_file_2.tftest.hcl", | ||
Status: moduletest.Skip, | ||
Runs: []*moduletest.Run{}, | ||
}, | ||
}, | ||
}, | ||
ExpectedNames: map[int]string{ | ||
0: "test_file_1.tftest.hcl", | ||
1: "test_file_2.tftest.hcl", | ||
2: "test_file_3.tftest.hcl", | ||
}, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
t.Run(tn, func(t *testing.T) { | ||
list := suiteFilesAsSortedList(tc.Suite.Files) | ||
|
||
if len(tc.ExpectedNames) != len(tc.Suite.Files) { | ||
t.Fatalf("expected there to be %d items, got %d", len(tc.ExpectedNames), len(tc.Suite.Files)) | ||
} | ||
|
||
if len(tc.ExpectedNames) == 0 { | ||
return | ||
} | ||
|
||
for k, v := range tc.ExpectedNames { | ||
if list[k].Name != v { | ||
t.Fatalf("expected element %d in sorted list to be named %s, got %s", k, v, list[k].Name) | ||
} | ||
} | ||
}) | ||
} | ||
} |