Skip to content

Commit

Permalink
Compare TaskResourceBindings in order agnostic manner
Browse files Browse the repository at this point in the history
The PipelineRun controller creates TaskResourceBindings by iterating
over maps, and iteration over maps is non-deterministic. The order of
these values in the result doesn't matter, so this commit updates the
tests to compare them regardless of order.

Part of #320
  • Loading branch information
bobcatfish authored and knative-prow-robot committed Jan 24, 2019
1 parent 39a0d6e commit b2732f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/knative/build-pipeline/pkg/apis/pipeline"
"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/knative/build-pipeline/pkg/reconciler"
Expand Down Expand Up @@ -203,7 +204,7 @@ func TestReconcile(t *testing.T) {
)

// ignore IgnoreUnexported ignore both after and before steps fields
if d := cmp.Diff(actual, expectedTaskRun); d != "" {
if d := cmp.Diff(actual, expectedTaskRun, cmpopts.SortSlices(func(x, y v1alpha1.TaskResourceBinding) bool { return x.Name < y.Name })); d != "" {
t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, d)
}
// test taskrun is able to recreate correct pipeline-pvc-name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/pipelinerun/resources"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -184,10 +185,10 @@ func Test_WrapSteps(t *testing.T) {
Paths: []string{"/pvc/test-task/test-output"},
}}

if d := cmp.Diff(taskRunSpec.Inputs.Resources, expectedtaskInputResources); d != "" {
if d := cmp.Diff(taskRunSpec.Inputs.Resources, expectedtaskInputResources, cmpopts.SortSlices(func(x, y v1alpha1.TaskResourceBinding) bool { return x.Name < y.Name })); d != "" {
t.Errorf("error comparing input resources: %s", d)
}
if d := cmp.Diff(taskRunSpec.Outputs.Resources, expectedtaskOuputResources); d != "" {
if d := cmp.Diff(taskRunSpec.Outputs.Resources, expectedtaskOuputResources, cmpopts.SortSlices(func(x, y v1alpha1.TaskResourceBinding) bool { return x.Name < y.Name })); d != "" {
t.Errorf("error comparing output resources: %s", d)
}
}

0 comments on commit b2732f3

Please sign in to comment.