2026-10-27 03:05:15 +00:00
|
|
|
package configkit_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"testing/fstest"
|
|
|
|
|
|
2026-11-01 14:19:37 +00:00
|
|
|
configkit "go.maximumdirect.net/configkit"
|
2026-10-27 03:05:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestOverlayExplanationUsesQueryScopedOrigin(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
filesystem := configkit.NewFilesystem("origin", fstest.MapFS{
|
|
|
|
|
"main.yml": {Data: []byte("a: base\ngroup: {x: X, y: Y}\n")},
|
|
|
|
|
"overlays/dev.yml": {Data: []byte("a: overlay\ngroup: {x: O}\n")},
|
|
|
|
|
})
|
|
|
|
|
result, err := configkit.Load[map[string]any](filesystem.File("main.yml"), configkit.Options[map[string]any]{Overlay: "dev"})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
|
path configkit.Path
|
|
|
|
|
line, column int
|
|
|
|
|
}{
|
|
|
|
|
{configkit.Keys(), 1, 1},
|
|
|
|
|
{configkit.Keys("group"), 2, 8},
|
|
|
|
|
{configkit.Keys("group", "x"), 2, 12},
|
|
|
|
|
} {
|
|
|
|
|
explanation, found := result.Explain(test.path)
|
|
|
|
|
if !found || len(explanation.History) == 0 {
|
|
|
|
|
t.Fatalf("missing explanation for %s", test.path)
|
|
|
|
|
}
|
|
|
|
|
origin := explanation.History[len(explanation.History)-1].Origin
|
|
|
|
|
if origin.Layer != configkit.LayerOverlay || len(origin.Locations) != 1 {
|
|
|
|
|
t.Fatalf("overlay origin for %s = %#v", test.path, origin)
|
|
|
|
|
}
|
|
|
|
|
location := origin.Locations[0]
|
|
|
|
|
if location.SourceID != "source-2" || location.Line != test.line || location.Column != test.column {
|
|
|
|
|
t.Fatalf("overlay location for %s = %#v; want line %d column %d", test.path, location, test.line, test.column)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|