Skip to content

Commit

Permalink
Fix flaky unit-test spec for Build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
qu1queee committed Feb 2, 2021
1 parent c0bfa60 commit a00ab1c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/validate/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validate
import (
"context"
"fmt"
"sort"
"strings"

build "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
Expand Down Expand Up @@ -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, ","))
Expand Down

0 comments on commit a00ab1c

Please sign in to comment.