diff --git a/integration/libs/git/git_fetch_test.go b/integration/libs/git/git_fetch_test.go index 06fa3b61f6..9c174c58e5 100644 --- a/integration/libs/git/git_fetch_test.go +++ b/integration/libs/git/git_fetch_test.go @@ -52,12 +52,15 @@ func TestFetchRepositoryInfoAPI_FromRepo(t *testing.T) { ctx = dbr.MockRuntime(ctx, dbr.Environment{IsDbr: true, Version: "15.4"}) - for _, inputPath := range []string{ - path.Join(targetPath, "knowledge_base/dashboard_nyc_taxi"), - targetPath, + for _, tc := range []struct { + name string + input string + }{ + {"subdir", path.Join(targetPath, "knowledge_base/dashboard_nyc_taxi")}, + {"root", targetPath}, } { - t.Run(inputPath, func(t *testing.T) { - info, err := git.FetchRepositoryInfo(ctx, inputPath, wt.W) + t.Run(tc.name, func(t *testing.T) { + info, err := git.FetchRepositoryInfo(ctx, tc.input, wt.W) assert.NoError(t, err) assertFullGitInfo(t, targetPath, info) }) @@ -75,25 +78,29 @@ func TestFetchRepositoryInfoAPI_FromNonRepo(t *testing.T) { ctx = dbr.MockRuntime(ctx, dbr.Environment{IsDbr: true, Version: "15.4"}) tests := []struct { + name string input string msg string }{ { + name: "subdir", input: path.Join(rootPath, "a/b/c"), msg: "", }, { + name: "root", input: rootPath, msg: "", }, { + name: "non-existent", input: path.Join(rootPath, "/non-existent"), msg: "doesn't exist", }, } for _, test := range tests { - t.Run(test.input+" <==> "+test.msg, func(t *testing.T) { + t.Run(test.name, func(t *testing.T) { info, err := git.FetchRepositoryInfo(ctx, test.input, wt.W) if test.msg == "" { assert.NoError(t, err) @@ -111,12 +118,15 @@ func TestFetchRepositoryInfoDotGit_FromGitRepo(t *testing.T) { repo := cloneRepoLocally(t, examplesRepoUrl) - for _, inputPath := range []string{ - filepath.Join(repo, "knowledge_base/dashboard_nyc_taxi"), - repo, + for _, tc := range []struct { + name string + input string + }{ + {"subdir", filepath.Join(repo, "knowledge_base/dashboard_nyc_taxi")}, + {"root", repo}, } { - t.Run(inputPath, func(t *testing.T) { - info, err := git.FetchRepositoryInfo(ctx, inputPath, wt.W) + t.Run(tc.name, func(t *testing.T) { + info, err := git.FetchRepositoryInfo(ctx, tc.input, wt.W) assert.NoError(t, err) assertFullGitInfo(t, repo, info) }) @@ -140,15 +150,18 @@ func TestFetchRepositoryInfoDotGit_FromNonGitRepo(t *testing.T) { root := filepath.Join(tempDir, "repo") require.NoError(t, os.MkdirAll(filepath.Join(root, "a/b/c"), 0o700)) - tests := []string{ - filepath.Join(root, "a/b/c"), - root, - filepath.Join(root, "/non-existent"), + tests := []struct { + name string + input string + }{ + {"subdir", filepath.Join(root, "a/b/c")}, + {"root", root}, + {"non-existent", filepath.Join(root, "/non-existent")}, } - for _, input := range tests { - t.Run(input, func(t *testing.T) { - info, err := git.FetchRepositoryInfo(ctx, input, wt.W) + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + info, err := git.FetchRepositoryInfo(ctx, test.input, wt.W) assert.ErrorIs(t, err, os.ErrNotExist) assertEmptyGitInfo(t, info) })