Skip to content

Commit

Permalink
Add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tothszabi committed Nov 12, 2024
1 parent ba85434 commit c8b0475
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,9 @@ func validatePipelines(config *BitriseDataModel) ([]string, error) {
// A pipeline is considered valid if it has neither stages nor workflows.
// This is useful for the WFE to be able to save a pipeline that is not yet fully defined.
if !hasStages && !hasWorkflows {
warning := fmt.Sprintf("pipeline (%s) should have at least 1 stage or workflow", pipelineID)
pipelineWarnings = append(pipelineWarnings, warning)

continue
}

Expand Down
66 changes: 66 additions & 0 deletions models/models_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,72 @@ func TestValidateConfig(t *testing.T) {
}
}

func TestValidatePipelines(t *testing.T) {
tests := []struct {
name string
config string
wantWarns []string
wantErr string
}{
{
name: "empty pipelines",
config: `
format_version: 11
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
pipelines:
pipeline1:
workflows: {}
pipeline2:
stages: []
`,
wantWarns: []string{
"pipeline (pipeline1) should have at least 1 stage or workflow",
"pipeline (pipeline2) should have at least 1 stage or workflow",
},
},
{
name: "mixed pipeline",
config: `
format_version: 11
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
pipelines:
pipeline1:
workflows:
workflow1: {}
stages:
- stage1: {}
stages:
stage1:
workflow1: {}
workflows:
workflow1: {}
`,
wantErr: "pipeline (pipeline1) has both stages and workflows",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var config BitriseDataModel
require.NoError(t, yaml.Unmarshal([]byte(tt.config), &config))

warns, err := config.Validate()
if len(tt.wantWarns) > 0 {
require.Equal(t, tt.wantWarns, warns)
} else {
require.Empty(t, warns)
}

if tt.wantErr != "" {
require.EqualError(t, err, tt.wantErr)
} else {
require.NoError(t, err)
}
})
}
}

func TestValidateConfig_Containers(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit c8b0475

Please sign in to comment.