Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky unit tests in resources package #438

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package resources_test

import (
"sort"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -25,7 +26,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Test_GetOutputSteps(t *testing.T) {
func TestGetOutputSteps(t *testing.T) {
r1 := &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "resource1",
Expand Down Expand Up @@ -70,14 +71,15 @@ func Test_GetOutputSteps(t *testing.T) {
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
postTasks := resources.GetOutputSteps(tc.outputs, tc.pipelineTaskName)
sort.SliceStable(postTasks, func(i, j int) bool { return postTasks[i].Name < postTasks[j].Name })
if d := cmp.Diff(postTasks, tc.expectedtaskOuputResources); d != "" {
t.Errorf("error comparing post steps: %s", d)
}
})
}
}

func Test_GetInputSteps(t *testing.T) {
func TestGetInputSteps(t *testing.T) {
r1 := &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "resource1",
Expand Down Expand Up @@ -136,6 +138,7 @@ func Test_GetInputSteps(t *testing.T) {
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
taskInputResources := resources.GetInputSteps(tc.inputs, tc.pipelineTask)
sort.SliceStable(taskInputResources, func(i, j int) bool { return taskInputResources[i].Name < taskInputResources[j].Name })
if d := cmp.Diff(tc.expectedtaskInputResources, taskInputResources); d != "" {
t.Errorf("error comparing task resource inputs: %s", d)
}
Expand All @@ -144,7 +147,7 @@ func Test_GetInputSteps(t *testing.T) {
}
}

func Test_WrapSteps(t *testing.T) {
func TestWrapSteps(t *testing.T) {
r1 := &v1alpha1.PipelineResource{
ObjectMeta: metav1.ObjectMeta{
Name: "resource1",
Expand Down Expand Up @@ -185,6 +188,9 @@ func Test_WrapSteps(t *testing.T) {
Paths: []string{"/pvc/test-task/test-output"},
}}

sort.SliceStable(expectedtaskInputResources, func(i, j int) bool { return expectedtaskInputResources[i].Name < expectedtaskInputResources[j].Name })
sort.SliceStable(expectedtaskOuputResources, func(i, j int) bool { return expectedtaskOuputResources[i].Name < expectedtaskOuputResources[j].Name })

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)
}
Expand Down