Index import dependencies for local scope scheduling
This commit is contained in:
@@ -1107,6 +1107,70 @@ id: item
|
||||
})
|
||||
}
|
||||
|
||||
func TestBroadItemScopesKeepHelperOriginsAndDestinations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type item struct {
|
||||
ID string `yaml:"id"`
|
||||
Value string `yaml:"value"`
|
||||
}
|
||||
type config struct {
|
||||
Items []item `yaml:"items"`
|
||||
}
|
||||
directory := t.TempDir()
|
||||
const count = 32
|
||||
var main strings.Builder
|
||||
main.WriteString("configkit:\n imports:\n")
|
||||
for index := count - 1; index >= 0; index-- {
|
||||
name := strconv.Itoa(100 + index)
|
||||
main.WriteString(" - path: item-" + name + ".yml\n destination: [items]\n placement: sequence-item\n")
|
||||
writeImportFile(t, directory, "item-"+name+".yml", "configkit: {imports: [{path: helper-"+name+".yml}]}\nid: item-"+name+"\n")
|
||||
writeImportFile(t, directory, "helper-"+name+".yml", "value: helper-"+name+"\n")
|
||||
}
|
||||
mainPath := writeImportFile(t, directory, "main.yml", main.String())
|
||||
definition := Definition[config]{sequenceIdentityRegistrations: []sequenceIdentityRegistration{{
|
||||
selector: sequenceIdentitySelector{literalSequenceSelector("items")}, identityFields: []string{"id"},
|
||||
}}}
|
||||
for _, layered := range []bool{false, true} {
|
||||
t.Run(strconv.FormatBool(layered), func(t *testing.T) {
|
||||
var loaded *Loaded[config]
|
||||
var err error
|
||||
if layered {
|
||||
loaded, err = LoadLayered(Input{Source: NoSource()}, testSecretBinding(), LayeredOptions[config]{
|
||||
Definition: definition,
|
||||
Underlays: []Underlay{{Inputs: []Input{{Source: File(mainPath), Imports: true}}}},
|
||||
})
|
||||
} else {
|
||||
loaded, err = Load(File(mainPath), testSecretBinding(), Options[config]{Imports: true, Definition: definition})
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := testLoaded(loaded)
|
||||
sources := result.Sources()
|
||||
if len(result.Config.Items) != count || len(sources) != 2*count+1 {
|
||||
t.Fatalf("item/source counts = %d/%d", len(result.Config.Items), len(sources))
|
||||
}
|
||||
metadata := result.Metadata()
|
||||
for index, record := range result.Config.Items {
|
||||
name := strconv.Itoa(100 + index)
|
||||
if record.ID != "item-"+name || record.Value != "helper-"+name {
|
||||
t.Fatalf("item %d = %#v", index, record)
|
||||
}
|
||||
// Acquisition remains authored (descending); final item order is
|
||||
// dependency-ready (ascending), with helper evidence reprojected.
|
||||
helper := sources[2*(count-index)]
|
||||
field, found := metadata.Lookup(Keys("items").Index(index).Key("value"))
|
||||
if !found || len(field.Origin.Locations) != 1 || field.Origin.Locations[0].SourceID != helper.ID ||
|
||||
helper.Path != canonicalTestPath(t, filepath.Join(directory, "helper-"+name+".yml")) ||
|
||||
helper.Destination.String() != Keys("items").Index(index).String() {
|
||||
t.Fatalf("item %d helper evidence = %#v, %#v", index, field, helper)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestItemHelperScopeScheduleInterleavesUnequalBranches(t *testing.T) {
|
||||
directory := t.TempDir()
|
||||
mainPath := writeImportFile(t, directory, "main.yml", `configkit:
|
||||
|
||||
Reference in New Issue
Block a user