Apply module scope to file validation checks
This commit is contained in:
@@ -29,9 +29,7 @@ func TestCheckLocalReplacementsParsesCommittedModuleDeclarations(t *testing.T) {
|
||||
t.Fatalf("checkLocalReplacements error = %v, want local-replacements failure", err)
|
||||
}
|
||||
want := map[string]Finding{
|
||||
"go.mod": {Path: "go.mod", Line: 3, Target: "../local module", Directive: "replace"},
|
||||
"nested/go.mod:4": {Path: "nested/go.mod", Line: 4, Target: "../../local", Directive: "replace"},
|
||||
"nested/go.mod:5": {Path: "nested/go.mod", Line: 5, Target: absoluteTarget, Directive: "replace"},
|
||||
"go.mod": {Path: "go.mod", Line: 3, Target: "../local module", Directive: "replace"},
|
||||
}
|
||||
if len(failure.Findings) != len(want) {
|
||||
t.Fatalf("findings = %#v, want %d filesystem replacements", failure.Findings, len(want))
|
||||
@@ -46,6 +44,27 @@ func TestCheckLocalReplacementsParsesCommittedModuleDeclarations(t *testing.T) {
|
||||
t.Errorf("finding = %#v, want %q", finding, key)
|
||||
}
|
||||
}
|
||||
|
||||
nestedTree, err := ReadCandidateTreeForScope(context.Background(), repository, commit, TreeScope{ModuleDir: filepath.Join(repository, "nested")})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cleanupCandidateTree(t, nestedTree)
|
||||
err = checkLocalReplacements(context.Background(), nestedTree)
|
||||
if !errors.As(err, &failure) || failure.Check != LocalReplacements || len(failure.Findings) != 2 {
|
||||
t.Fatalf("nested replacement findings = %#v, want the selected module's two replacements", err)
|
||||
}
|
||||
for _, finding := range failure.Findings {
|
||||
wantLine := 4
|
||||
wantTarget := "../../local"
|
||||
if finding.Line == 5 {
|
||||
wantLine = 5
|
||||
wantTarget = absoluteTarget
|
||||
}
|
||||
if finding.Path != "nested/go.mod" || finding.Line != wantLine || finding.Target != wantTarget || finding.Directive != "replace" {
|
||||
t.Errorf("nested finding = %#v, want line %d target %q", finding, wantLine, wantTarget)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckLocalReplacementsFollowsCommittedModuleSymlinks(t *testing.T) {
|
||||
@@ -58,7 +77,7 @@ func TestCheckLocalReplacementsFollowsCommittedModuleSymlinks(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
commit := commitCandidateTree(t, repository)
|
||||
tree, err := ReadCandidateTree(context.Background(), repository, commit)
|
||||
tree, err := ReadCandidateTreeForScope(context.Background(), repository, commit, TreeScope{ModuleDir: filepath.Join(repository, "nested")})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -91,7 +110,10 @@ func TestCheckLocalReplacementsSharesSummariesAcrossModuleSymlinks(t *testing.T)
|
||||
}
|
||||
}
|
||||
commit := commitCandidateTree(t, repository)
|
||||
tree, err := ReadCandidateTree(context.Background(), repository, commit)
|
||||
tree, err := ReadCandidateTreeForScope(context.Background(), repository, commit, TreeScope{
|
||||
ModuleDir: repository,
|
||||
SharedFiles: []string{"first/go.mod", "second/go.mod"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user