Migrate structural and inspection fixtures
This commit is contained in:
@@ -7,6 +7,28 @@ import (
|
||||
"testing/fstest"
|
||||
)
|
||||
|
||||
func TestNestedConfigDataSurvivesCompositionAndPrecedence(t *testing.T) {
|
||||
loaded, err := testGroupedLoad(loadRequest[map[string]any]{
|
||||
main: loadInput{source: Bytes("main", []byte("service: {config: {enabled: false, count: 0}}\n"))},
|
||||
underlays: []loadGroup{{inputs: []loadInput{
|
||||
{source: Bytes("left", []byte("service: {config: {enabled: true, empty: ''}}\n"))},
|
||||
{source: Bytes("right", []byte("service: {config: {count: 3, optional: null}}\n"))},
|
||||
}}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values := loaded.Config["service"].(map[string]any)["config"].(map[string]any)
|
||||
if values["enabled"] != false || values["count"] != int64(0) || values["empty"] != "" || values["optional"] != nil {
|
||||
t.Fatalf("composed data = %#v", values)
|
||||
}
|
||||
for _, key := range []string{"enabled", "count", "empty", "optional"} {
|
||||
if info, ok := loaded.Metadata().Lookup(Keys("service", "config", key)); !ok || !info.Explicit {
|
||||
t.Errorf("presence for %s = %#v, %t", key, info, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedCollectionInitializationIsIndependentOfAncestorPresence(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, ancestor := range []string{"{}", "group: {}", "group: null"} {
|
||||
@@ -24,7 +46,7 @@ func TestNestedCollectionInitializationIsIndependentOfAncestorPresence(t *testin
|
||||
{mode: "upsert", key: ", key: id", value: "[]", valid: true},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%s/%s/%s/%s", ancestor, test.mode, test.key, test.value), func(t *testing.T) {
|
||||
main := "configkit:\n sequences: [{destination: [group, items], mode: " + test.mode + test.key + "}]\ngroup: {items: " + test.value + "}\n"
|
||||
main := "config:\n sequences: [{destination: [group, items], mode: " + test.mode + test.key + "}]\ngroup: {items: " + test.value + "}\n"
|
||||
loaded, err := testGroupedLoad(loadRequest[map[string]any]{
|
||||
main: loadInput{source: Bytes("main", []byte(main))},
|
||||
underlays: []loadGroup{{inputs: []loadInput{{source: Bytes("lower", []byte(ancestor))}}}},
|
||||
@@ -60,13 +82,13 @@ func TestAddedAncestorTransfersNestedRecordPolicies(t *testing.T) {
|
||||
} `yaml:"group"`
|
||||
}
|
||||
files := fstest.MapFS{
|
||||
"main.yml": {Data: []byte(`configkit:
|
||||
"main.yml": {Data: []byte(`config:
|
||||
sequences: [{destination: [group, items], key: id}]
|
||||
imports: [{path: base.yml, destination: [group, items], placement: sequence-item}]
|
||||
group:
|
||||
items: [{id: child, extends: {id: base}, steps: [{name: child}]}]
|
||||
`)},
|
||||
"base.yml": {Data: []byte("configkit:\n sequences: [{destination: [steps], key: name}]\nid: base\nsteps: [{name: base}]\n")},
|
||||
"base.yml": {Data: []byte("config:\n sequences: [{destination: [steps], key: name}]\nid: base\nsteps: [{name: base}]\n")},
|
||||
}
|
||||
loaded, err := testGroupedLoad(loadRequest[config]{
|
||||
main: loadInput{source: NewFilesystem("catalog", files).File("main.yml"), imports: true},
|
||||
@@ -88,7 +110,7 @@ group:
|
||||
|
||||
func TestInheritanceChecksCollectionOperationUnderAddedAncestor(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := testLoad[map[string]any](Bytes("inheritance", []byte(`configkit:
|
||||
_, err := testLoad[map[string]any](Bytes("inheritance", []byte(`config:
|
||||
sequences: [{destination: [child, group, items], mode: append}]
|
||||
base: {}
|
||||
child:
|
||||
|
||||
Reference in New Issue
Block a user