diff --git a/pkg/osvscanner/fixtures/example-git-with-submodule/submodule-test/b.txt b/pkg/osvscanner/fixtures/example-git-with-submodule/submodule-test/b.txt index ba7a9d8edf..bfb689ae5d 100644 --- a/pkg/osvscanner/fixtures/example-git-with-submodule/submodule-test/b.txt +++ b/pkg/osvscanner/fixtures/example-git-with-submodule/submodule-test/b.txt @@ -1,2 +1 @@ submodule test file -new diff --git a/pkg/osvscanner/osvscanner_internal_test.go b/pkg/osvscanner/osvscanner_internal_test.go index 8c121a2b47..816e633917 100644 --- a/pkg/osvscanner/osvscanner_internal_test.go +++ b/pkg/osvscanner/osvscanner_internal_test.go @@ -113,53 +113,52 @@ func Test_getSubmodulesVia_scanGit(t *testing.T) { } } -// func Test_scanGit(t *testing.T) { -// t.Parallel() - -// type args struct { -// r reporter.Reporter -// repoDir string -// } -// tests := []struct { -// name string -// args args -// wantErr bool -// wantPkg []scannedPackage -// }{ -// { -// name: "Example Git repo", -// args: args{ -// r: &reporter.VoidReporter{}, -// repoDir: "fixtures/example-git", -// }, -// wantErr: false, -// wantPkg: []scannedPackage{ -// { -// Commit: "862ac4bd2703b622e85f29f55a2fd8cd6caf8182", -// Source: models.SourceInfo{ -// Path: "fixtures/example-git", -// Type: "git", -// }, -// }, -// }, -// }, -// } - -// makeGitFixtureDotGit(t) -// defer makeGitFixtureHiddenGit(t) - -// for _, tt := range tests { -// pkg, err := scanGit(tt.args.r, tt.args.repoDir) -// if (err != nil) != tt.wantErr { -// t.Errorf("scanGit() error = %v, wantErr %v", err, tt.wantErr) -// } -// if diff := cmp.Diff(tt.wantPkg, pkg); diff != "" { -// t.Errorf("scanGit() package = %v, wantPackage %v", pkg, tt.wantPkg) -// } -// } -// } - -// TODO: make Errorf, Fatalf +func Test_scanGit(t *testing.T) { + t.Parallel() + + type args struct { + r reporter.Reporter + repoDir string + } + tests := []struct { + name string + args args + wantErr bool + wantPkg []scannedPackage + }{ + { + name: "Example Git repo", + args: args{ + r: &reporter.VoidReporter{}, + repoDir: "fixtures/example-git", + }, + wantErr: false, + wantPkg: []scannedPackage{ + { + Commit: "862ac4bd2703b622e85f29f55a2fd8cd6caf8182", + Source: models.SourceInfo{ + Path: "fixtures/example-git", + Type: "git", + }, + }, + }, + }, + } + + makeGitFixtureDotGit(t) + defer makeGitFixtureHiddenGit(t) + + for _, tt := range tests { + pkg, err := scanGit(tt.args.r, tt.args.repoDir) + if (err != nil) != tt.wantErr { + t.Errorf("scanGit() error = %v, wantErr %v", err, tt.wantErr) + } + if diff := cmp.Diff(tt.wantPkg, pkg); diff != "" { + t.Errorf("scanGit() package = %v, wantPackage %v", pkg, tt.wantPkg) + } + } +} + func makeSubmodulesFixtureDotGit(t *testing.T) { t.Helper() @@ -191,20 +190,20 @@ func makeSubmodulesFixtureHiddenGit(t *testing.T) { } } -// func makeGitFixtureDotGit(t *testing.T) { -// t.Helper() +func makeGitFixtureDotGit(t *testing.T) { + t.Helper() -// err := os.Rename("fixtures/example-git/git-hidden", "fixtures/example-git/.git") -// if err != nil { -// t.Errorf("can't find git-hidden folder") -// } -// } + err := os.Rename("fixtures/example-git/git-hidden", "fixtures/example-git/.git") + if err != nil { + t.Fatalf("can't rename git-hidden folder: %s", err) + } +} -// func makeGitFixtureHiddenGit(t *testing.T) { -// t.Helper() +func makeGitFixtureHiddenGit(t *testing.T) { + t.Helper() -// err := os.Rename("fixtures/example-git/.git", "fixtures/example-git/git-hidden") -// if err != nil { -// t.Errorf("can't find .git folder") -// } -// } + err := os.Rename("fixtures/example-git/.git", "fixtures/example-git/git-hidden") + if err != nil { + t.Fatalf("can't rename git-hidden folder: %s", err) + } +}