Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions integration/libs/git/git_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand Down
Loading