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
3 changes: 2 additions & 1 deletion pkg/validation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ func validateReleaseTagConfiguration(fieldRoot string, input api.ReleaseTagConfi
func validateReleaseBuildConfiguration(input *api.ReleaseBuildConfiguration, org, repo string) []error {
var validationErrors []error

if len(input.Tests) == 0 && len(input.Images) == 0 {
// Third conjunct is a corner case, the config can e.g. promote its `src`
if len(input.Tests) == 0 && len(input.Images) == 0 && (input.PromotionConfiguration == nil || len(input.PromotionConfiguration.AdditionalImages) == 0) {
validationErrors = append(validationErrors, errors.New("you must define at least one test or image build in 'tests' or 'images'"))
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/validation/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,30 @@ func TestPipelineImages(t *testing.T) {
})
}
}

func TestValidateReleaseBuildConfiguration(t *testing.T) {
testCases := []struct {
name string
input *api.ReleaseBuildConfiguration
expected []error
}{
{
name: "empty images and tests -> error",
input: &api.ReleaseBuildConfiguration{},
expected: []error{errors.New("you must define at least one test or image build in 'tests' or 'images'")},
},
{
name: "empty images and tests -> not error if additional images are promoted",
input: &api.ReleaseBuildConfiguration{
PromotionConfiguration: &api.PromotionConfiguration{AdditionalImages: map[string]string{"name": "src"}},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.input.Resources = map[string]api.ResourceRequirements{"*": {Requests: map[string]string{"cpu": "1"}}}
err := validateReleaseBuildConfiguration(tc.input, "org", "repo")
testhelper.Diff(t, "error", err, tc.expected, testhelper.EquateErrorMessage)
})
}
}