Migrate acquisition fixtures to document-root controls
This commit is contained in:
@@ -13,17 +13,52 @@ type importDestinationConfig struct {
|
||||
Collections map[string]map[string]string `yaml:"collections"`
|
||||
}
|
||||
|
||||
func TestImportsKeepDocumentControlsBeforePlacement(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
main := writeImportFile(t, directory, "main.yml", "config: {imports: [{path: parent.yml, destination: [config]}]}\n")
|
||||
parent := writeImportFile(t, directory, "parent.yml", "config: {imports: [{path: leaf.yml, destination: [config]}]}\nimports: ordinary\n")
|
||||
leaf := writeImportFile(t, directory, "leaf.yml", "sequences: ordinary\n")
|
||||
loaded, err := LoadLayered(Input{Source: File(main), Imports: true}, testSecretBinding(), LayeredOptions[map[string]any]{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := loaded.Config["config"].(map[string]any)
|
||||
if root["imports"] != "ordinary" || root["config"].(map[string]any)["sequences"] != "ordinary" {
|
||||
t.Fatalf("assembled configuration = %#v", loaded.Config)
|
||||
}
|
||||
sources := testLoaded(loaded).Sources()
|
||||
if len(sources) != 3 || sources[1].Path != canonicalTestPath(t, parent) || sources[1].Destination.String() != "/config" || sources[2].Path != canonicalTestPath(t, leaf) || sources[2].Destination.String() != "/config/config" || sources[2].ImportedFrom == nil {
|
||||
t.Fatalf("sources = %#v", sources)
|
||||
}
|
||||
if info, ok := testLoaded(loaded).Metadata().Lookup(Keys("config", "config", "sequences")); !ok || len(info.Origin.Locations) == 0 || info.Origin.Locations[0].SourceID != sources[2].ID {
|
||||
t.Fatalf("leaf attribution = %#v, %t", info, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportsLeaveNestedConfigDataUntouched(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
main := writeImportFile(t, directory, "main.yml", "nested: {config: {imports: ordinary}}\n")
|
||||
loaded, err := LoadLayered(Input{Source: File(main), Imports: true}, testSecretBinding(), LayeredOptions[map[string]any]{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nested := loaded.Config["nested"].(map[string]any)["config"].(map[string]any)
|
||||
if nested["imports"] != "ordinary" {
|
||||
t.Fatalf("nested data = %#v", nested)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLayeredHostImportsInheritInputDestinationTransitively(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `config:
|
||||
imports:
|
||||
- path: first.yml
|
||||
- path: second.yml
|
||||
root: main
|
||||
`)
|
||||
firstPath := writeImportFile(t, directory, "first.yml", `configkit:
|
||||
firstPath := writeImportFile(t, directory, "first.yml", `config:
|
||||
imports:
|
||||
- path: nested/third.yml
|
||||
first: one
|
||||
@@ -52,7 +87,7 @@ first: one
|
||||
t.Errorf("mounted[%q] = %q, want %q", key, result.Config.Mounted[key], value)
|
||||
}
|
||||
}
|
||||
if _, ok := result.Metadata().Lookup(Keys("mounted", "configkit")); ok {
|
||||
if _, ok := result.Metadata().Lookup(Keys("mounted", "config")); ok {
|
||||
t.Fatal("source-root import directive leaked into application content")
|
||||
}
|
||||
sources := result.Sources()
|
||||
@@ -77,13 +112,13 @@ func TestImportTraversalUsesPerDeclarationDestinations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `config:
|
||||
imports:
|
||||
- path: parent.yml
|
||||
- path: sibling.yml
|
||||
- glob: fragments/*.yml
|
||||
`)
|
||||
parentPath := writeImportFile(t, directory, "parent.yml", `configkit:
|
||||
parentPath := writeImportFile(t, directory, "parent.yml", `config:
|
||||
imports:
|
||||
- path: nested/child.yml
|
||||
parent: true
|
||||
@@ -163,7 +198,7 @@ func TestEntryDestinationSurvivesImportSetupAndParseFailures(t *testing.T) {
|
||||
|
||||
t.Run("import context failure", func(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "configkit: {imports: [{path: child.yml}]}\n")
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "config: {imports: [{path: child.yml}]}\n")
|
||||
input, diagnostics := testAcquireInput(inputAcquisitionRequest{
|
||||
input: loadInput{source: File(mainPath), imports: true, filesystem: &FilesystemContext{Root: t.TempDir()}, destination: Keys("mounted")},
|
||||
role: sourceVersionMain, directiveContext: rootDirectiveContextImportsOnly,
|
||||
@@ -178,7 +213,7 @@ func TestEntryDestinationSurvivesImportSetupAndParseFailures(t *testing.T) {
|
||||
|
||||
t.Run("imported parse failure", func(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "configkit: {imports: [{path: broken.yml}]}\n")
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "config: {imports: [{path: broken.yml}]}\n")
|
||||
writeImportFile(t, directory, "broken.yml", "broken: [\n")
|
||||
input, diagnostics := testAcquireInput(inputAcquisitionRequest{
|
||||
input: loadInput{source: File(mainPath), imports: true, destination: Keys("mounted")},
|
||||
@@ -211,39 +246,39 @@ func TestRelativeImportDestinationsKeepStrictCompositionBoundaries(t *testing.T)
|
||||
}{
|
||||
{
|
||||
name: "disjoint peers at one destination",
|
||||
main: "configkit:\n imports:\n - path: left.yml\n destination: [application]\n - path: right.yml\n destination: [application]\n",
|
||||
main: "config:\n imports:\n - path: left.yml\n destination: [application]\n - path: right.yml\n destination: [application]\n",
|
||||
files: map[string]string{"left.yml": "left: one\n", "right.yml": "right: two\n"},
|
||||
want: map[string]any{"/application/left": "one", "/application/right": "two"},
|
||||
},
|
||||
{
|
||||
name: "different destinations",
|
||||
main: "configkit:\n imports:\n - path: left.yml\n destination: [left]\n - path: right.yml\n destination: [right]\n",
|
||||
main: "config:\n imports:\n - path: left.yml\n destination: [left]\n - path: right.yml\n destination: [right]\n",
|
||||
files: map[string]string{"left.yml": "value: shared\n", "right.yml": "value: shared\n"},
|
||||
want: map[string]any{"/left/value": "shared", "/right/value": "shared"},
|
||||
},
|
||||
{
|
||||
name: "ancestor and descendant overlap",
|
||||
main: "configkit:\n imports:\n - path: parent.yml\n destination: [application]\n - path: child.yml\n destination: [application, branch]\n",
|
||||
main: "config:\n imports:\n - path: parent.yml\n destination: [application]\n - path: child.yml\n destination: [application, branch]\n",
|
||||
files: map[string]string{"parent.yml": "branch: {base: one}\n", "child.yml": "leaf: two\n"},
|
||||
want: map[string]any{"/application/branch/base": "one", "/application/branch/leaf": "two"},
|
||||
},
|
||||
{
|
||||
name: "collision with explicitly wrapped content",
|
||||
main: "configkit: {imports: [{path: fragment.yml, destination: [application]}]}\napplication: {value: root}\n",
|
||||
main: "config: {imports: [{path: fragment.yml, destination: [application]}]}\napplication: {value: root}\n",
|
||||
files: map[string]string{"fragment.yml": "value: imported\n"},
|
||||
conflict: true,
|
||||
wantPath: "/application/value",
|
||||
},
|
||||
{
|
||||
name: "equal peer values conflict",
|
||||
main: "configkit:\n imports:\n - path: left.yml\n destination: [application]\n - path: right.yml\n destination: [application]\n",
|
||||
main: "config:\n imports:\n - path: left.yml\n destination: [application]\n - path: right.yml\n destination: [application]\n",
|
||||
files: map[string]string{"left.yml": "value: same\n", "right.yml": "value: same\n"},
|
||||
conflict: true,
|
||||
wantPath: "/application/value",
|
||||
},
|
||||
{
|
||||
name: "unequal peer values conflict",
|
||||
main: "configkit:\n imports:\n - path: left.yml\n destination: [application]\n - path: right.yml\n destination: [application]\n",
|
||||
main: "config:\n imports:\n - path: left.yml\n destination: [application]\n - path: right.yml\n destination: [application]\n",
|
||||
files: map[string]string{"left.yml": "value: left\n", "right.yml": "value: right\n"},
|
||||
conflict: true,
|
||||
wantPath: "/application/value",
|
||||
@@ -291,7 +326,7 @@ func TestRelativeImportDestinationsKeepStrictCompositionBoundaries(t *testing.T)
|
||||
|
||||
t.Run("upper tier cannot repair a lower import conflict", func(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
lowerPath := writeImportFile(t, directory, "lower.yml", `configkit:
|
||||
lowerPath := writeImportFile(t, directory, "lower.yml", `config:
|
||||
imports:
|
||||
- path: left.yml
|
||||
destination: [application]
|
||||
@@ -324,12 +359,12 @@ func TestRelativeImportDestinationsUseEffectiveVersionOwnership(t *testing.T) {
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `config:
|
||||
imports:
|
||||
- path: parent.yml
|
||||
destination: [group]
|
||||
`)
|
||||
writeImportFile(t, directory, "parent.yml", `configkit:
|
||||
writeImportFile(t, directory, "parent.yml", `config:
|
||||
imports:
|
||||
- path: fragment.yml
|
||||
destination: [nested]
|
||||
@@ -374,13 +409,13 @@ func TestRelativeImportDestinationsKeepMainVersionCheckScoped(t *testing.T) {
|
||||
} `yaml:"collection"`
|
||||
}
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `config:
|
||||
imports:
|
||||
- path: parent.yml
|
||||
destination: [group]
|
||||
schema_version: 6
|
||||
`)
|
||||
writeImportFile(t, directory, "parent.yml", `configkit:
|
||||
writeImportFile(t, directory, "parent.yml", `config:
|
||||
imports:
|
||||
- path: fragment.yml
|
||||
destination: [nested]
|
||||
@@ -421,8 +456,8 @@ func TestLayeredNativeFilesystemImportsInheritInputDestination(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
native := fstest.MapFS{
|
||||
"main.yml": &fstest.MapFile{Data: []byte("configkit:\n imports:\n - path: first.yml\nroot: main\n")},
|
||||
"first.yml": &fstest.MapFile{Data: []byte("configkit: {imports: [{path: nested.yml}]}\nfirst: imported\n")},
|
||||
"main.yml": &fstest.MapFile{Data: []byte("config:\n imports:\n - path: first.yml\nroot: main\n")},
|
||||
"first.yml": &fstest.MapFile{Data: []byte("config: {imports: [{path: nested.yml}]}\nfirst: imported\n")},
|
||||
"nested.yml": &fstest.MapFile{Data: []byte("nested: imported\n")},
|
||||
}
|
||||
namespace := newNativeNamespace("bundle", native)
|
||||
@@ -451,7 +486,7 @@ func TestLayeredImportOnlyInputMaterializesDestination(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `config:
|
||||
imports:
|
||||
- path: optional.yml
|
||||
`)
|
||||
@@ -489,7 +524,7 @@ func TestLayeredImportedVersionClaimsUseEffectiveDestination(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
directory := t.TempDir()
|
||||
writeImportFile(t, directory, "main.yml", "configkit: {imports: [{path: fragment.yml}]}\n")
|
||||
writeImportFile(t, directory, "main.yml", "config: {imports: [{path: fragment.yml}]}\n")
|
||||
writeImportFile(t, directory, "fragment.yml", "version: v2\n")
|
||||
rule := &VersionRule{Path: test.rulePath, Check: func(Version, *Validation) error { return nil }}
|
||||
loaded, err := LoadLayered(
|
||||
@@ -534,7 +569,7 @@ func TestLayeredDestinationsDoNotChangeRepeatedSourceIdentity(t *testing.T) {
|
||||
|
||||
directory := t.TempDir()
|
||||
writeImportFile(t, directory, "shared.yml", "value: shared\n")
|
||||
importerPath := writeImportFile(t, directory, "importer.yml", "configkit: {imports: [{path: shared.yml, destination: [nested]}]}\n")
|
||||
importerPath := writeImportFile(t, directory, "importer.yml", "config: {imports: [{path: shared.yml, destination: [nested]}]}\n")
|
||||
_, err := LoadLayered(
|
||||
Input{Source: NoSource()},
|
||||
testSecretBinding(),
|
||||
@@ -558,8 +593,8 @@ func TestLayeredDestinationsDoNotChangeRepeatedSourceIdentity(t *testing.T) {
|
||||
t.Run("placement does not break a physical cycle", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "configkit: {imports: [{path: parent.yml, destination: [one]}]}\n")
|
||||
writeImportFile(t, directory, "parent.yml", "configkit: {imports: [{path: main.yml, destination: [two]}]}\n")
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "config: {imports: [{path: parent.yml, destination: [one]}]}\n")
|
||||
writeImportFile(t, directory, "parent.yml", "config: {imports: [{path: main.yml, destination: [two]}]}\n")
|
||||
_, err := LoadLayered(Input{Source: File(mainPath), Imports: true}, testSecretBinding(), LayeredOptions[map[string]any]{})
|
||||
loadError, ok := err.(*LoadError)
|
||||
if !ok || len(loadError.Diagnostics()) == 0 || loadError.Diagnostics()[0].Code != CodeImportCycle {
|
||||
|
||||
Reference in New Issue
Block a user