Skip to content

Commit ea9ff34

Browse files
authored
integration/git: use static subtest names in TestFetchRepositoryInfo* (#5375)
The `TestFetchRepositoryInfo*` tests in `integration/libs/git` passed runtime values into `t.Run` — temporary workspace paths containing UUIDs and `t.TempDir()` paths — so each subtest got a different name on every run. In aggregated test output this shows up as thousands of distinct one-off test names instead of a single stable entry. This replaces the dynamic names with static ones (`subdir`, `root`, `non-existent`) by giving each table case an explicit `name` field. A sweep over every `t.Run` call in the repository found this to be the only place with this pattern. This pull request and its description were written by Isaac.
1 parent 13b7260 commit ea9ff34

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

integration/libs/git/git_fetch_test.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ func TestFetchRepositoryInfoAPI_FromRepo(t *testing.T) {
5252

5353
ctx = dbr.MockRuntime(ctx, dbr.Environment{IsDbr: true, Version: "15.4"})
5454

55-
for _, inputPath := range []string{
56-
path.Join(targetPath, "knowledge_base/dashboard_nyc_taxi"),
57-
targetPath,
55+
for _, tc := range []struct {
56+
name string
57+
input string
58+
}{
59+
{"subdir", path.Join(targetPath, "knowledge_base/dashboard_nyc_taxi")},
60+
{"root", targetPath},
5861
} {
59-
t.Run(inputPath, func(t *testing.T) {
60-
info, err := git.FetchRepositoryInfo(ctx, inputPath, wt.W)
62+
t.Run(tc.name, func(t *testing.T) {
63+
info, err := git.FetchRepositoryInfo(ctx, tc.input, wt.W)
6164
assert.NoError(t, err)
6265
assertFullGitInfo(t, targetPath, info)
6366
})
@@ -75,25 +78,29 @@ func TestFetchRepositoryInfoAPI_FromNonRepo(t *testing.T) {
7578
ctx = dbr.MockRuntime(ctx, dbr.Environment{IsDbr: true, Version: "15.4"})
7679

7780
tests := []struct {
81+
name string
7882
input string
7983
msg string
8084
}{
8185
{
86+
name: "subdir",
8287
input: path.Join(rootPath, "a/b/c"),
8388
msg: "",
8489
},
8590
{
91+
name: "root",
8692
input: rootPath,
8793
msg: "",
8894
},
8995
{
96+
name: "non-existent",
9097
input: path.Join(rootPath, "/non-existent"),
9198
msg: "doesn't exist",
9299
},
93100
}
94101

95102
for _, test := range tests {
96-
t.Run(test.input+" <==> "+test.msg, func(t *testing.T) {
103+
t.Run(test.name, func(t *testing.T) {
97104
info, err := git.FetchRepositoryInfo(ctx, test.input, wt.W)
98105
if test.msg == "" {
99106
assert.NoError(t, err)
@@ -111,12 +118,15 @@ func TestFetchRepositoryInfoDotGit_FromGitRepo(t *testing.T) {
111118

112119
repo := cloneRepoLocally(t, examplesRepoUrl)
113120

114-
for _, inputPath := range []string{
115-
filepath.Join(repo, "knowledge_base/dashboard_nyc_taxi"),
116-
repo,
121+
for _, tc := range []struct {
122+
name string
123+
input string
124+
}{
125+
{"subdir", filepath.Join(repo, "knowledge_base/dashboard_nyc_taxi")},
126+
{"root", repo},
117127
} {
118-
t.Run(inputPath, func(t *testing.T) {
119-
info, err := git.FetchRepositoryInfo(ctx, inputPath, wt.W)
128+
t.Run(tc.name, func(t *testing.T) {
129+
info, err := git.FetchRepositoryInfo(ctx, tc.input, wt.W)
120130
assert.NoError(t, err)
121131
assertFullGitInfo(t, repo, info)
122132
})
@@ -140,15 +150,18 @@ func TestFetchRepositoryInfoDotGit_FromNonGitRepo(t *testing.T) {
140150
root := filepath.Join(tempDir, "repo")
141151
require.NoError(t, os.MkdirAll(filepath.Join(root, "a/b/c"), 0o700))
142152

143-
tests := []string{
144-
filepath.Join(root, "a/b/c"),
145-
root,
146-
filepath.Join(root, "/non-existent"),
153+
tests := []struct {
154+
name string
155+
input string
156+
}{
157+
{"subdir", filepath.Join(root, "a/b/c")},
158+
{"root", root},
159+
{"non-existent", filepath.Join(root, "/non-existent")},
147160
}
148161

149-
for _, input := range tests {
150-
t.Run(input, func(t *testing.T) {
151-
info, err := git.FetchRepositoryInfo(ctx, input, wt.W)
162+
for _, test := range tests {
163+
t.Run(test.name, func(t *testing.T) {
164+
info, err := git.FetchRepositoryInfo(ctx, test.input, wt.W)
152165
assert.ErrorIs(t, err, os.ErrNotExist)
153166
assertEmptyGitInfo(t, info)
154167
})

0 commit comments

Comments
 (0)