Carry collection selections through configuration
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestReferenceSourceMapsConflictPreservesTrimmedSourceKinds(t *testing.T) {
|
||||
@@ -35,6 +38,53 @@ func TestReferenceSourceMapsConflictPreservesTrimmedSourceKinds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReferenceCollectionResolutionAndCopy(t *testing.T) {
|
||||
pipelineSource := ReferenceSource{Path: "base.yml", Collections: []string{"base"}}
|
||||
localSource := ReferenceSource{Path: "local.yml", Collections: []string{}}
|
||||
target := referenceResolutionTarget{
|
||||
PipelineID: "demo", Stage: StageExtract, Module: "extractor",
|
||||
Slots: []contracts.ReferenceSlot{{Name: "glossary"}},
|
||||
PipelineReferences: map[string]ReferenceSource{"glossary": pipelineSource},
|
||||
LocalReferences: map[string]ReferenceSource{"glossary": localSource},
|
||||
}
|
||||
bindings, err := resolveReferenceTargetBindings(target)
|
||||
if err != nil || len(bindings) != 1 || bindings[0].Source != "local.yml" || bindings[0].Collections == nil || len(bindings[0].Collections) != 0 {
|
||||
t.Fatalf("local binding = %#v, %v", bindings, err)
|
||||
}
|
||||
target.LocalReferences["glossary"] = ReferenceSource{Path: "other.yml"}
|
||||
bindings, err = resolveReferenceTargetBindings(target)
|
||||
if err != nil || bindings[0].Collections != nil {
|
||||
t.Fatalf("replacement inherited collections: %#v, %v", bindings, err)
|
||||
}
|
||||
target.LocalReferences = nil
|
||||
bindings, err = resolveReferenceTargetBindings(target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bindings[0].Collections[0] = "changed"
|
||||
if pipelineSource.Collections[0] != "base" {
|
||||
t.Fatal("binding selection aliases input")
|
||||
}
|
||||
profile := ClonePipelineProfile(PipelineProfile{References: map[string]ReferenceSource{"glossary": pipelineSource, "empty": localSource}})
|
||||
profile.References["glossary"].Collections[0] = "changed"
|
||||
if pipelineSource.Collections[0] != "base" || profile.References["empty"].Collections == nil {
|
||||
t.Fatal("profile clone lost selection isolation or explicit emptiness")
|
||||
}
|
||||
withEmpty, err := json.Marshal(localSource)
|
||||
if err != nil || !strings.Contains(string(withEmpty), `"collections":[]`) {
|
||||
t.Fatalf("encoded reference = %s, %v", withEmpty, err)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
selection []string
|
||||
wantEmpty bool
|
||||
}{{nil, false}, {[]string{}, true}} {
|
||||
encoded, err := json.Marshal(ReferenceBinding{SlotName: "glossary", Collections: test.selection})
|
||||
if err != nil || strings.Contains(string(encoded), `"collections":[]`) != test.wantEmpty {
|
||||
t.Fatalf("encoded binding = %s, %v", encoded, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeTargetReferenceSourceOwnsAndValidatesSelector(t *testing.T) {
|
||||
target := referenceResolutionTarget{PipelineID: "demo", StepID: "consumer", LaneID: "lane", Stage: StageExtract, Module: "extractor"}
|
||||
input := ReferenceSource{Artifact: &ArtifactReference{Step: " producer ", Lane: " output "}}
|
||||
|
||||
Reference in New Issue
Block a user