From c8b0475c4c12e841da9087b9db1ae7f18fb69cb6 Mon Sep 17 00:00:00 2001 From: Szabolcs Toth <54896607+tothszabi@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:30:39 +0100 Subject: [PATCH] Add warning --- models/models_methods.go | 3 ++ models/models_methods_test.go | 66 +++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/models/models_methods.go b/models/models_methods.go index f067d46e..e530a7a9 100644 --- a/models/models_methods.go +++ b/models/models_methods.go @@ -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 } diff --git a/models/models_methods_test.go b/models/models_methods_test.go index 64265d00..b95001cb 100644 --- a/models/models_methods_test.go +++ b/models/models_methods_test.go @@ -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