From 4477be81e75a2f87619c088f01893861698f989c Mon Sep 17 00:00:00 2001 From: bells17 Date: Wed, 11 May 2022 01:53:33 +0900 Subject: [PATCH 1/2] Fix error message Update pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go Oh...thanks. Co-authored-by: Kensei Nakada --- .../plugins/volumebinding/volume_binding_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go index 8c5c6fe8c05..a6ff23dea57 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go @@ -18,7 +18,6 @@ package volumebinding import ( "context" - "reflect" "testing" "github.com/google/go-cmp/cmp" @@ -654,8 +653,8 @@ func TestVolumeBinding(t *testing.T) { t.Logf("Verify: call PreFilter and check status") _, gotPreFilterStatus := p.PreFilter(ctx, state, item.pod) - if !reflect.DeepEqual(gotPreFilterStatus, item.wantPreFilterStatus) { - t.Errorf("filter prefilter status does not match: %v, want: %v", gotPreFilterStatus, item.wantPreFilterStatus) + if diff := cmp.Diff(item.wantPreFilterStatus, gotPreFilterStatus); diff != "" { + t.Errorf("prefilter status does not match: (-want,+got):\n%s", diff) } if !gotPreFilterStatus.IsSuccess() { // scheduler framework will skip Filter if PreFilter fails @@ -678,8 +677,8 @@ func TestVolumeBinding(t *testing.T) { t.Logf("Verify: call Filter and check status") for i, nodeInfo := range nodeInfos { gotStatus := p.Filter(ctx, state, item.pod, nodeInfo) - if !reflect.DeepEqual(gotStatus, item.wantFilterStatus[i]) { - t.Errorf("filter status does not match for node %q, got: %v, want: %v", nodeInfo.Node().Name, gotStatus, item.wantFilterStatus) + if diff := cmp.Diff(item.wantFilterStatus[i], gotStatus); diff != "" { + t.Errorf("filter status does not match for node %q, (-want,+got):\n%s", nodeInfo.Node().Name, diff) } } From e539e041031038c83ba8274bc873888cff8fb63a Mon Sep 17 00:00:00 2001 From: bells17 Date: Fri, 5 Aug 2022 00:54:19 +0900 Subject: [PATCH 2/2] Use stretchr/testify/assert --- .../plugins/volumebinding/volume_binding_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go index a6ff23dea57..eaa6c391eff 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" + "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -653,9 +654,7 @@ func TestVolumeBinding(t *testing.T) { t.Logf("Verify: call PreFilter and check status") _, gotPreFilterStatus := p.PreFilter(ctx, state, item.pod) - if diff := cmp.Diff(item.wantPreFilterStatus, gotPreFilterStatus); diff != "" { - t.Errorf("prefilter status does not match: (-want,+got):\n%s", diff) - } + assert.Equal(t, item.wantPreFilterStatus, gotPreFilterStatus) if !gotPreFilterStatus.IsSuccess() { // scheduler framework will skip Filter if PreFilter fails return @@ -677,9 +676,7 @@ func TestVolumeBinding(t *testing.T) { t.Logf("Verify: call Filter and check status") for i, nodeInfo := range nodeInfos { gotStatus := p.Filter(ctx, state, item.pod, nodeInfo) - if diff := cmp.Diff(item.wantFilterStatus[i], gotStatus); diff != "" { - t.Errorf("filter status does not match for node %q, (-want,+got):\n%s", nodeInfo.Node().Name, diff) - } + assert.Equal(t, item.wantFilterStatus[i], gotStatus) } t.Logf("Verify: Score")