Strengthen composition and import selection tests
This commit is contained in:
@@ -161,8 +161,21 @@ func TestSelectNamedImportsChecksNormalizedPathsLexically(t *testing.T) {
|
||||
if len(diagnostics) != 0 || len(selection.candidates) != 2 {
|
||||
t.Fatalf("selection, diagnostics = %#v, %#v", selection, diagnostics)
|
||||
}
|
||||
if strings.Join(filesystem.statPaths, ",") != "a.yaml,a.yaml,z.yaml,z.yaml" {
|
||||
t.Fatalf("target stat order = %#v", filesystem.statPaths)
|
||||
if selection.candidates[0].path != "a.yaml" || selection.candidates[1].path != "z.yaml" {
|
||||
t.Fatalf("candidate order = %#v, want a.yaml then z.yaml", selection.candidates)
|
||||
}
|
||||
|
||||
failingFilesystem := &statOnlyImportFilesystem{statErrors: map[string]error{
|
||||
"a.yaml": fs.ErrPermission,
|
||||
"z.yaml": fs.ErrPermission,
|
||||
}}
|
||||
failingAccess := newNativeAccess(failingFilesystem, ".", &namespaceToken{})
|
||||
_, diagnostics = selectNamedImportCandidates(failingAccess, ".", specs[0], resolvedImportPolicy{})
|
||||
if len(diagnostics) != 1 || diagnostics[0].Code != CodeImportInvalid || diagnostics[0].Path.String() != "/configkit/imports/0/path/1" {
|
||||
t.Fatalf("first lexical failure = %#v, want /configkit/imports/0/path/1", diagnostics)
|
||||
}
|
||||
if diagnostics[0].Primary == nil || diagnostics[0].Primary.SourceID != "source-1" {
|
||||
t.Fatalf("first lexical failure location = %#v", diagnostics[0].Primary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +239,6 @@ type statOnlyImportFilesystem struct {
|
||||
statErrors map[string]error
|
||||
openCalls int
|
||||
statCalls int
|
||||
statPaths []string
|
||||
}
|
||||
|
||||
func (filesystem *statOnlyImportFilesystem) Open(name string) (fs.File, error) {
|
||||
@@ -236,7 +248,6 @@ func (filesystem *statOnlyImportFilesystem) Open(name string) (fs.File, error) {
|
||||
|
||||
func (filesystem *statOnlyImportFilesystem) Stat(name string) (fs.FileInfo, error) {
|
||||
filesystem.statCalls++
|
||||
filesystem.statPaths = append(filesystem.statPaths, name)
|
||||
if err := filesystem.statErrors[name]; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user