Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler/native/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,17 @@ func validatePipelineStages(s pipeline.StageSlice) error {
reportMap := make(map[string]string)
reportCount := 0

nameMap := make(map[string]bool)
stageNameMap := make(map[string]bool)
stepNameMap := make(map[string]bool)

for _, stage := range s {
err := validatePipelineContainers(stage.Steps, &reportCount, reportMap, nameMap, stage.Name)
if _, ok := stageNameMap[stage.Name]; ok {
return fmt.Errorf("stage `%s` is already defined", stage.Name)
}

stageNameMap[stage.Name] = true

err := validatePipelineContainers(stage.Steps, &reportCount, reportMap, stepNameMap, stage.Name)
if err != nil {
return err
}
Expand Down
45 changes: 45 additions & 0 deletions compiler/native/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,51 @@ func TestNative_Validate_Stages(t *testing.T) {
}
}

func TestNative_Validate_StagesSameName(t *testing.T) {
// setup types
strFoo := "foo"
strBar := "bar"

p := &pipeline.Build{
Version: "v1",
Stages: pipeline.StageSlice{
&pipeline.Stage{
Name: strFoo,
Steps: pipeline.ContainerSlice{
&pipeline.Container{
Commands: raw.StringSlice{"echo hello"},
Image: "alpine",
Name: strFoo,
Pull: "always",
},
},
},
&pipeline.Stage{
Name: strFoo,
Steps: pipeline.ContainerSlice{
&pipeline.Container{
Commands: raw.StringSlice{"echo hello"},
Image: "alpine",
Name: strBar,
Pull: "always",
},
},
},
},
}

// run test
compiler, err := FromCLICommand(context.Background(), testCommand(t, "http://foo.example.com"))
if err != nil {
t.Errorf("Unable to create new compiler: %v", err)
}

err = compiler.ValidatePipeline(p)
if err == nil {
t.Errorf("Validate should have returned err")
}
}

func TestNative_Validate_Stages_NoName(t *testing.T) {
// setup types
str := "foo"
Expand Down
2 changes: 2 additions & 0 deletions router/middleware/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestMiddleware_TracingInstrumentation(t *testing.T) {
if !reflect.DeepEqual(got, trace.SpanContext{}) {
return errors.New("span context is not empty")
}

return nil
},
},
Expand All @@ -82,6 +83,7 @@ func TestMiddleware_TracingInstrumentation(t *testing.T) {
if reflect.DeepEqual(got, trace.SpanContext{}) {
return errors.New("span context is empty")
}

return nil
},
},
Expand Down