Rename selected configuration profiles to overlays
This commit is contained in:
@@ -16,7 +16,7 @@ type layeredConfig struct {
|
||||
Shared struct {
|
||||
Equal string `yaml:"equal"`
|
||||
Imported string `yaml:"imported"`
|
||||
Profile string `yaml:"profile"`
|
||||
Overlay string `yaml:"overlay"`
|
||||
} `yaml:"shared"`
|
||||
Values []int `yaml:"values"`
|
||||
Items map[string]layeredItem `yaml:"items"`
|
||||
@@ -40,7 +40,7 @@ nullable: base
|
||||
empty: {}
|
||||
`)
|
||||
importPath := writeImportFile(t, directory, "imported.yml", "shared: {imported: base}\n")
|
||||
profilePath := writeImportFile(t, directory, "profiles/testing.yml", `shared: {profile: selected}
|
||||
overlayPath := writeImportFile(t, directory, "overlays/testing.yml", `shared: {overlay: selected}
|
||||
values: [3, 4]
|
||||
value: selected
|
||||
nullable: null
|
||||
@@ -71,23 +71,23 @@ empty: {}
|
||||
}
|
||||
|
||||
result, err := testLoad[layeredConfig](File(mainPath), Options[layeredConfig]{
|
||||
Imports: true, Profile: "testing", Definition: definition,
|
||||
Imports: true, Overlay: "testing", Definition: definition,
|
||||
})
|
||||
if err != nil {
|
||||
var loadError *LoadError
|
||||
_ = errors.As(err, &loadError)
|
||||
t.Fatalf("%v: %#v", err, loadError.Diagnostics())
|
||||
}
|
||||
wantSources := []string{canonicalTestPath(t, mainPath), canonicalTestPath(t, importPath), canonicalTestPath(t, profilePath)}
|
||||
wantSources := []string{canonicalTestPath(t, mainPath), canonicalTestPath(t, importPath), canonicalTestPath(t, overlayPath)}
|
||||
sources := result.Sources()
|
||||
gotSources := make([]string, len(sources))
|
||||
for index, source := range sources {
|
||||
gotSources[index] = source.Path
|
||||
}
|
||||
if !reflect.DeepEqual(gotSources, wantSources) || sources[2].Layer != LayerProfile {
|
||||
if !reflect.DeepEqual(gotSources, wantSources) || sources[2].Layer != LayerOverlay {
|
||||
t.Fatalf("sources = %#v", sources)
|
||||
}
|
||||
if result.Config.Shared.Equal != "same" || result.Config.Shared.Imported != "base" || result.Config.Shared.Profile != "selected" ||
|
||||
if result.Config.Shared.Equal != "same" || result.Config.Shared.Imported != "base" || result.Config.Shared.Overlay != "selected" ||
|
||||
!reflect.DeepEqual(result.Config.Values, []int{5}) || result.Config.Nullable != nil || result.Config.Derived != 7 ||
|
||||
result.Config.Empty["retained"] != "default" {
|
||||
t.Fatalf("configuration = %#v", result.Config)
|
||||
@@ -100,13 +100,13 @@ empty: {}
|
||||
empty, _ := metadata.Lookup(Keys("empty"))
|
||||
firstValue, _ := metadata.Lookup(Keys("values").Index(0))
|
||||
if !equal.Explicit || equal.Origin.Layer != LayerBase || derived.Explicit || derived.Origin.Operation != ChangeDerivedDefault ||
|
||||
!nullable.Explicit || !nullable.Null || nullable.Origin.Layer != LayerProfile ||
|
||||
!empty.Explicit || empty.Origin.Layer != LayerProfile || len(empty.Origin.Locations) != 2 ||
|
||||
!nullable.Explicit || !nullable.Null || nullable.Origin.Layer != LayerOverlay ||
|
||||
!empty.Explicit || empty.Origin.Layer != LayerOverlay || len(empty.Origin.Locations) != 2 ||
|
||||
!firstValue.Explicit || firstValue.Origin.Operation != ChangeNormalization {
|
||||
t.Fatalf("metadata = equal %#v derived %#v nullable %#v empty %#v value %#v", equal, derived, nullable, empty, firstValue)
|
||||
}
|
||||
if _, ok := metadata.Lookup(Keys("value", "child")); ok {
|
||||
t.Fatal("profile-removed child remains effective")
|
||||
t.Fatal("overlay-removed child remains effective")
|
||||
}
|
||||
if _, ok := metadata.Lookup(Keys("values").Index(1)); ok {
|
||||
t.Fatal("resolution-removed sequence index remains effective")
|
||||
@@ -116,10 +116,10 @@ empty: {}
|
||||
}
|
||||
|
||||
assertHistoryLayersAndPaths(t, metadata.History(Keys("values").Index(1)),
|
||||
[]Layer{LayerDefault, LayerBase, LayerProfile, LayerResolution},
|
||||
[]Layer{LayerDefault, LayerBase, LayerOverlay, LayerResolution},
|
||||
[]string{"/values/1", "/values/1", "/values", "/values"})
|
||||
assertHistoryLayersAndPaths(t, metadata.History(Keys("value", "child")),
|
||||
[]Layer{LayerDefault, LayerBase, LayerProfile},
|
||||
[]Layer{LayerDefault, LayerBase, LayerOverlay},
|
||||
[]string{"/value/child", "/value/child", "/value"})
|
||||
removedHistory := metadata.History(Keys("items", "remove", "value"))
|
||||
assertHistoryLayersAndPaths(t, removedHistory,
|
||||
@@ -159,11 +159,11 @@ empty: {}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedProfileLoadsRemainIndependentConcurrently(t *testing.T) {
|
||||
func TestSelectedOverlayLoadsRemainIndependentConcurrently(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", "values: [1, 2]\n")
|
||||
writeImportFile(t, directory, "profiles/testing.yml", "values: [3, 4]\n")
|
||||
options := Options[layeredConfig]{Profile: "testing"}
|
||||
writeImportFile(t, directory, "overlays/testing.yml", "values: [3, 4]\n")
|
||||
options := Options[layeredConfig]{Overlay: "testing"}
|
||||
|
||||
const loads = 16
|
||||
results := make(chan *testResult[layeredConfig], loads)
|
||||
@@ -200,7 +200,7 @@ func TestSelectedProfileLoadsRemainIndependentConcurrently(t *testing.T) {
|
||||
if !reflect.DeepEqual(result.Config.Values, []int{3, 4}) {
|
||||
t.Fatalf("concurrent result contaminated = %#v", result.Config.Values)
|
||||
}
|
||||
if info, ok := result.Metadata().Lookup(Keys("values")); !ok || info.Origin.Layer != LayerProfile {
|
||||
if info, ok := result.Metadata().Lookup(Keys("values")); !ok || info.Origin.Layer != LayerOverlay {
|
||||
t.Fatalf("concurrent metadata contaminated = %#v, %v", info, ok)
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ sequence: [first, second]
|
||||
composite: {first: first}
|
||||
`)
|
||||
secondPath := writeImportFile(t, directory, "second.yml", "composite: {second: second}\n")
|
||||
profilePath := writeImportFile(t, directory, "profiles/testing.yml", "equal: same\nprofile: profile\n")
|
||||
overlayPath := writeImportFile(t, directory, "overlays/testing.yml", "equal: same\noverlay: overlay\n")
|
||||
compositeSources := map[string]bool{
|
||||
canonicalTestPath(t, mainPath): true,
|
||||
canonicalTestPath(t, firstPath): true,
|
||||
@@ -232,12 +232,12 @@ composite: {first: first}
|
||||
Sequence []string `yaml:"sequence"`
|
||||
Composite map[string]string `yaml:"composite"`
|
||||
Equal string `yaml:"equal"`
|
||||
Profile string `yaml:"profile"`
|
||||
Overlay string `yaml:"overlay"`
|
||||
CLIEqual string `yaml:"cli_equal"`
|
||||
}
|
||||
var callbackErr error
|
||||
result, err := testLoad[config](File(mainPath), Options[config]{
|
||||
Imports: true, Profile: "testing", Overrides: []Override{{Path: Keys("cli_equal"), Value: "same", Flag: "--cli-equal"}},
|
||||
Imports: true, Overlay: "testing", Overrides: []Override{{Path: Keys("cli_equal"), Value: "same", Flag: "--cli-equal"}},
|
||||
Definition: Definition[config]{Resolve: func(_ *config, resolution *Resolution) error {
|
||||
check := func(ok bool, message string) {
|
||||
if !ok && callbackErr == nil {
|
||||
@@ -257,9 +257,9 @@ composite: {first: first}
|
||||
fileOwner(Keys("main"), canonicalTestPath(t, mainPath))
|
||||
fileOwner(Keys("imported"), canonicalTestPath(t, firstPath))
|
||||
fileOwner(Keys("sequence").Index(1), canonicalTestPath(t, firstPath))
|
||||
profile := fileOwner(Keys("equal"), canonicalTestPath(t, profilePath))
|
||||
fileOwner(Keys("profile"), canonicalTestPath(t, profilePath))
|
||||
check(profile.Origin.Layer == LayerProfile, "profile replacement retained base ownership")
|
||||
overlay := fileOwner(Keys("equal"), canonicalTestPath(t, overlayPath))
|
||||
fileOwner(Keys("overlay"), canonicalTestPath(t, overlayPath))
|
||||
check(overlay.Origin.Layer == LayerOverlay, "overlay replacement retained base ownership")
|
||||
cli, found := resolution.InputInfo(Keys("cli_equal"))
|
||||
check(found && cli.Origin.Layer == LayerCLI && len(cli.Origin.Locations) == 1, "CLI replacement lost ownership")
|
||||
if found && len(cli.Origin.Locations) == 1 {
|
||||
@@ -298,7 +298,7 @@ composite: {first: first}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Config.Main != "main" || result.Config.Imported != "imported" || !reflect.DeepEqual(result.Config.Sequence, []string{"first", "second"}) ||
|
||||
result.Config.Equal != "same" || result.Config.Profile != "profile" || result.Config.CLIEqual != "same" {
|
||||
result.Config.Equal != "same" || result.Config.Overlay != "overlay" || result.Config.CLIEqual != "same" {
|
||||
t.Fatalf("configuration = %#v", result.Config)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user