Share catalog-independent pipeline layout
This commit is contained in:
22
internal/core/config/layout_contract_test.go
Normal file
22
internal/core/config/layout_contract_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
)
|
||||
|
||||
func TestValidateUsesMapIdentityWithoutMutatingProfile(t *testing.T) {
|
||||
cfg := Default()
|
||||
cfg.Pipelines[" demo "] = pipeline.PipelineProfile{Artifacts: map[string]pipeline.ArtifactLaneProfile{" lane ": {}}}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
profile := cfg.Pipelines[" demo "]
|
||||
if profile.ID != "" || len(profile.Artifacts) != 1 {
|
||||
t.Fatalf("validation mutated profile: %#v", profile)
|
||||
}
|
||||
if _, ok := profile.Artifacts[" lane "]; !ok {
|
||||
t.Fatalf("validation changed lane identity: %#v", profile.Artifacts)
|
||||
}
|
||||
}
|
||||
@@ -57,45 +57,20 @@ func validatePipelineProfiles(profiles map[string]pipeline.PipelineProfile) erro
|
||||
if err := validateReferenceMap(id, "", profile.References); err != nil {
|
||||
return err
|
||||
}
|
||||
explicitSteps := profile.Steps != nil
|
||||
if len(profile.Artifacts) > 0 && explicitSteps {
|
||||
return fmt.Errorf("pipeline %q must not declare both artifacts and steps", id)
|
||||
layoutProfile := profile
|
||||
layoutProfile.ID = id
|
||||
layout, err := pipeline.LayoutPipeline(layoutProfile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
steps := profile.Steps
|
||||
if !explicitSteps {
|
||||
steps = []pipeline.PipelineStepProfile{{ID: "default", Artifacts: profile.Artifacts}}
|
||||
}
|
||||
if explicitSteps && len(steps) == 0 {
|
||||
return fmt.Errorf("pipeline %q must declare at least one ordered step", id)
|
||||
}
|
||||
seenSteps := make(map[string]struct{}, len(steps))
|
||||
seenLanes := make(map[string]struct{})
|
||||
for index, step := range steps {
|
||||
stepID := strings.TrimSpace(step.ID)
|
||||
if stepID == "" {
|
||||
return fmt.Errorf("pipeline %q step[%d] id must not be empty", id, index)
|
||||
}
|
||||
if _, ok := seenSteps[stepID]; ok {
|
||||
return fmt.Errorf("pipeline %q step id %q is duplicated after trimming", id, stepID)
|
||||
}
|
||||
seenSteps[stepID] = struct{}{}
|
||||
if explicitSteps {
|
||||
if err := validateReferenceMapForContext(id, "", "step "+stepID, step.References, true); err != nil {
|
||||
for _, step := range layout.Steps {
|
||||
if layout.ExplicitSteps {
|
||||
if err := validateReferenceMapForContext(id, "", "step "+step.ID, step.References, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for rawLaneID, lane := range step.Artifacts {
|
||||
laneID := strings.TrimSpace(rawLaneID)
|
||||
if laneID == "" {
|
||||
return fmt.Errorf("pipeline %q artifact lane id must not be empty", id)
|
||||
}
|
||||
if _, ok := seenLanes[laneID]; ok {
|
||||
if !explicitSteps {
|
||||
return fmt.Errorf("pipeline %q artifact lane id %q is duplicated after trimming", id, laneID)
|
||||
}
|
||||
return fmt.Errorf("pipeline %q artifact lane id %q is duplicated across steps", id, laneID)
|
||||
}
|
||||
seenLanes[laneID] = struct{}{}
|
||||
for _, laneID := range step.LaneIDs {
|
||||
lane := step.Artifacts[laneID]
|
||||
if err := validateReferenceMapForContext(id, laneID, "", lane.References, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user