Skip to content

Commit

Permalink
test unknown steps fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Dec 13, 2023
1 parent ea99103 commit 96b9546
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/pipeline/prepare_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (ctx *pipelineContext) getEnvironmentSubPipelinesToRun() ([]model.Environme
})
}
}
err := commonErrors.Concat(errs)
err := errors.Join(errs...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func (ctx *pipelineContext) createPipeline(envName string, pipeline *pipelinev1.
var errs []error
taskMap, err := ctx.buildTasks(envName, tasks, timestamp)
if err != nil {
errs = append(errs, fmt.Errorf("failed to build task for pipeline %s: %s", originalPipelineName, err))
errs = append(errs, fmt.Errorf("failed to build task for pipeline %s: %w", originalPipelineName, err))
}

for i, pipelineSpecTask := range pipeline.Spec.Tasks {
Expand All @@ -373,7 +373,7 @@ func (ctx *pipelineContext) createPipeline(envName string, pipeline *pipelinev1.
pipeline.Spec.Tasks[i].TaskRef = &pipelinev1.TaskRef{Name: task.Name}
}
if len(errs) > 0 {
return commonErrors.Concat(errs)
return errors.Join(errs...)
}
pipelineName := fmt.Sprintf("radix-pipeline-%s-%s-%s-%s", getShortName(envName), getShortName(originalPipelineName), timestamp, ctx.hash)
pipeline.ObjectMeta.Name = pipelineName
Expand Down
25 changes: 25 additions & 0 deletions pkg/pipeline/prepare_pipelines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/utils"
radixclientfake "github.com/equinor/radix-operator/pkg/client/clientset/versioned/fake"
"github.com/equinor/radix-tekton/pkg/models/env"
"github.com/equinor/radix-tekton/pkg/pipeline/validation"
"github.com/equinor/radix-tekton/pkg/utils/labels"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -520,6 +521,30 @@ func Test_pipelineContext_createPipeline(t *testing.T) {
assert.Contains(t, skipContainers, "prepare")
},
},
{
name: "Test unknown steps is not allowed in sanitizeAzureSkipContainersAnnotation",
args: args{
envName: envDev,
pipeline: getTestPipeline(func(pipeline *pipelinev1.Pipeline) {
pipeline.ObjectMeta.Name = "pipeline1"
pipeline.Spec.Tasks = append(pipeline.Spec.Tasks, pipelinev1.PipelineTask{Name: "identity", TaskRef: &pipelinev1.TaskRef{Name: "task1"}})
}),
tasks: []pipelinev1.Task{{
ObjectMeta: metav1.ObjectMeta{
Name: "task1",
Annotations: map[string]string{"azure.workload.identity/skip-containers": "skip-id;unknown-step"},
Labels: map[string]string{labels.AzureWorkloadIdentityUse: "true"},
},
Spec: pipelinev1.TaskSpec{Steps: []pipelinev1.Step{
{Name: "get-secret"}, {Name: "skip-id"}},
}},
},
},
wantErr: func(t *testing.T, err error) {
assert.ErrorIs(t, err, validation.ErrSkipStepNotFound)
},
assertScenario: func(t *testing.T, ctx *pipelineContext, pipelineName string) {},
},
}
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
Expand Down

0 comments on commit 96b9546

Please sign in to comment.