From a00ab1cb879f9d309410d30a08c7731f45cca4c9 Mon Sep 17 00:00:00 2001 From: Enrique Encalada Date: Tue, 2 Feb 2021 10:01:20 +0100 Subject: [PATCH] Fix flaky unit-test spec for Build We assert for a combination of secret names under Status.Message when the secrets validation fails. Because the list of secrets comes from a map and a map is an unordered collection of key-value pairs, this commits adds a sort, to ensure an ordered list in Status.Message and for avoiding the flakiness in the unit-test spec. --- pkg/validate/secrets.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/validate/secrets.go b/pkg/validate/secrets.go index 60ff1f90c0..d611b52891 100644 --- a/pkg/validate/secrets.go +++ b/pkg/validate/secrets.go @@ -3,6 +3,7 @@ package validate import ( "context" "fmt" + "sort" "strings" build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" @@ -37,6 +38,9 @@ func (s SecretRef) ValidatePath(ctx context.Context) error { } } + // sorts a list of secret names in increasing order + sort.Strings(missingSecrets) + if len(missingSecrets) > 1 { s.Build.Status.Reason = build.MultipleSecretRefNotFound s.Build.Status.Message = fmt.Sprintf("missing secrets are %s", strings.Join(missingSecrets, ","))