Check native overlay link targets
This commit is contained in:
@@ -218,3 +218,43 @@ func TestLayeredOverlayNativeContext(t *testing.T) {
|
||||
}
|
||||
t.Fatalf("diagnostics = %#v", err.(*configkit.LoadError).Diagnostics())
|
||||
}
|
||||
|
||||
func TestLayeredOverlayNativeLinks(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, mainPath, target string
|
||||
want configkit.Code
|
||||
}{
|
||||
{"outside root", "scope/main.yml", "../../outside.yml", configkit.CodeOverlayOutsideRoot},
|
||||
{"overlay aliases main", "scope/main.yml", "../main.yml", configkit.CodeOverlayRepeated},
|
||||
{"main aliases overlay target", "scope/alias.yml", "../target.yml", configkit.CodeOverlayRepeated},
|
||||
{"contained overlay", "scope/main.yml", "../target.yml", ""},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
native := configkit.NewFilesystem("bundle", fstest.MapFS{
|
||||
"scope/main.yml": {Data: []byte("count: 1\n")},
|
||||
"scope/alias.yml": {Data: []byte("target.yml"), Mode: os.ModeSymlink},
|
||||
"scope/target.yml": {Data: []byte("count: 7\n")},
|
||||
"scope/overlays/test.yml": {Data: []byte(tc.target), Mode: os.ModeSymlink},
|
||||
"outside.yml": {Data: []byte("count: 9\n")},
|
||||
})
|
||||
main := configkit.Input{Source: native.File(tc.mainPath), Filesystem: &configkit.FilesystemContext{Root: "scope", FS: &native}}
|
||||
result, err := configkit.LoadLayered(main, configkit.LayeredOptions[layeredFacadeConfig]{Overlay: "test"})
|
||||
if tc.want != "" {
|
||||
if err == nil {
|
||||
t.Fatal("overlay link unexpectedly loaded")
|
||||
}
|
||||
diagnostics := err.(*configkit.LoadError).Diagnostics()
|
||||
if len(diagnostics) != 1 || diagnostics[0].Code != tc.want {
|
||||
t.Fatalf("diagnostics = %#v, want %v", diagnostics, tc.want)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Config.Count != 7 || result.Sources()[1].Path != "scope/target.yml" {
|
||||
t.Fatalf("config = %#v, sources = %#v", result.Config, result.Sources())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user