Preserve failing search candidate diagnostics
This commit is contained in:
@@ -157,6 +157,56 @@ func TestSearchSelectedFileFailuresDoNotFallBack(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSearchProbeFailureRetainsFileEvidence(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
root := t.TempDir()
|
||||
main := writeImportFile(t, root, "main.yml", "value: main\n")
|
||||
underlay := writeImportFile(t, root, "underlay.yml", "settings: {first: underlay}\n")
|
||||
bad := filepath.Join(main, "child.yml")
|
||||
later := writeImportFile(t, root, "later.yml", "value: later\n")
|
||||
missing := filepath.Join(root, "missing.yml")
|
||||
for _, entry := range []struct {
|
||||
name string
|
||||
id string
|
||||
load func(Source) (*Loaded[discoveryLoadConfig], error)
|
||||
}{
|
||||
{"ordinary", "source-1", func(source Source) (*Loaded[discoveryLoadConfig], error) {
|
||||
return Load(source, testSecretBinding(), Options[discoveryLoadConfig]{destination: Keys("settings")})
|
||||
}},
|
||||
{"underlay after acquired sources", "source-3", func(source Source) (*Loaded[discoveryLoadConfig], error) {
|
||||
return LoadLayered(Input{Source: File(main)}, testSecretBinding(), LayeredOptions[discoveryLoadConfig]{
|
||||
Underlays: []Underlay{{Inputs: []Input{
|
||||
{Source: File(underlay)}, {Source: source, Destination: Keys("service", "settings")},
|
||||
}}},
|
||||
})
|
||||
}},
|
||||
} {
|
||||
t.Run(entry.name, func(t *testing.T) {
|
||||
_, err := entry.load(File(bad))
|
||||
var explicit *LoadError
|
||||
if !errors.As(err, &explicit) || len(explicit.Diagnostics()) != 1 {
|
||||
t.Fatalf("explicit failed file = %v", err)
|
||||
}
|
||||
if explicit.Diagnostics()[0].Code == CodeSourceMissing {
|
||||
t.Skip("host classifies a non-directory ancestor as absence; controlled probe tests cover access failures")
|
||||
}
|
||||
result, err := entry.load(SearchConfig("", Paths(missing, bad, later)))
|
||||
var searched *LoadError
|
||||
if result != nil || !errors.As(err, &searched) {
|
||||
t.Fatalf("failed search = %#v, %v", result, err)
|
||||
}
|
||||
if !reflect.DeepEqual(searched.Sources(), explicit.Sources()) || !reflect.DeepEqual(searched.Diagnostics(), explicit.Diagnostics()) {
|
||||
t.Fatalf("search failure differs from explicit file:\nsources %#v / %#v\ndiagnostics %#v / %#v", searched.Sources(), explicit.Sources(), searched.Diagnostics(), explicit.Diagnostics())
|
||||
}
|
||||
primary := searched.Diagnostics()[0].Primary
|
||||
if primary == nil || primary.SourceID != entry.id {
|
||||
t.Fatalf("failed candidate location = %#v, want %s", primary, entry.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchValidationPrecedesCandidateProbing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user