mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 18:58:18 +00:00
Replace uses of reflect.DeepEqual with cmp.Diff in pkg/scheduler tests
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -72,11 +71,14 @@ const (
|
||||
var _ framework.ScorePlugin = &TestScoreWithNormalizePlugin{}
|
||||
var _ framework.ScorePlugin = &TestScorePlugin{}
|
||||
|
||||
var cmpOpts = []cmp.Option{
|
||||
var statusCmpOpts = []cmp.Option{
|
||||
cmp.Comparer(func(s1 *framework.Status, s2 *framework.Status) bool {
|
||||
if s1 == nil || s2 == nil {
|
||||
return s1.IsSuccess() && s2.IsSuccess()
|
||||
}
|
||||
if s1.Code() == framework.Error {
|
||||
return s1.AsError().Error() == s2.AsError().Error()
|
||||
}
|
||||
return s1.Code() == s2.Code() && s1.Plugin() == s2.Plugin() && s1.Message() == s2.Message()
|
||||
}),
|
||||
}
|
||||
@@ -924,7 +926,7 @@ func TestNewFrameworkMultiPointExpansion(t *testing.T) {
|
||||
}
|
||||
if tc.wantErr == "" {
|
||||
if diff := cmp.Diff(tc.wantPlugins, fw.ListPlugins()); diff != "" {
|
||||
t.Fatalf("Unexpected eventToPlugin map (-want,+got):%s", diff)
|
||||
t.Fatalf("Unexpected eventToPlugin map (-want,+got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -982,8 +984,8 @@ func TestPreEnqueuePlugins(t *testing.T) {
|
||||
_ = f.Close()
|
||||
}()
|
||||
got := f.PreEnqueuePlugins()
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("PreEnqueuePlugins(): want %v, but got %v", tt.want, got)
|
||||
if diff := cmp.Diff(tt.want, got); diff != "" {
|
||||
t.Errorf("Unexpected PreEnqueuePlugins(): (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1113,8 +1115,8 @@ func TestRunPreScorePlugins(t *testing.T) {
|
||||
t.Errorf("wrong status code. got: %v, want: %v", status, tt.wantStatusCode)
|
||||
}
|
||||
skipped := state.SkipScorePlugins
|
||||
if d := cmp.Diff(skipped, tt.wantSkippedPlugins); d != "" {
|
||||
t.Errorf("wrong skip score plugins. got: %v, want: %v, diff: %s", skipped, tt.wantSkippedPlugins, d)
|
||||
if diff := cmp.Diff(tt.wantSkippedPlugins, skipped); diff != "" {
|
||||
t.Errorf("wrong skip score plugins (-want, +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1519,8 +1521,8 @@ func TestRunScorePlugins(t *testing.T) {
|
||||
if !status.IsSuccess() {
|
||||
t.Errorf("Expected status to be success.")
|
||||
}
|
||||
if !reflect.DeepEqual(res, tt.want) {
|
||||
t.Errorf("Score map after RunScorePlugin. got: %+v, want: %+v.", res, tt.want)
|
||||
if diff := cmp.Diff(tt.want, res); diff != "" {
|
||||
t.Errorf("Score map after RunScorePlugin (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1747,15 +1749,15 @@ func TestRunPreFilterPlugins(t *testing.T) {
|
||||
|
||||
state := framework.NewCycleState()
|
||||
result, status, _ := f.RunPreFilterPlugins(ctx, state, nil)
|
||||
if d := cmp.Diff(result, tt.wantPreFilterResult); d != "" {
|
||||
t.Errorf("wrong status. got: %v, want: %v, diff: %s", result, tt.wantPreFilterResult, d)
|
||||
if diff := cmp.Diff(tt.wantPreFilterResult, result); diff != "" {
|
||||
t.Errorf("wrong status (-want,+got):\n%s", diff)
|
||||
}
|
||||
if status.Code() != tt.wantStatusCode {
|
||||
t.Errorf("wrong status code. got: %v, want: %v", status, tt.wantStatusCode)
|
||||
}
|
||||
skipped := state.SkipFilterPlugins
|
||||
if d := cmp.Diff(skipped, tt.wantSkippedPlugins); d != "" {
|
||||
t.Errorf("wrong skip filter plugins. got: %v, want: %v, diff: %s", skipped, tt.wantSkippedPlugins, d)
|
||||
if diff := cmp.Diff(tt.wantSkippedPlugins, skipped); diff != "" {
|
||||
t.Errorf("wrong skip filter plugins (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2136,8 +2138,8 @@ func TestFilterPlugins(t *testing.T) {
|
||||
state := framework.NewCycleState()
|
||||
state.SkipFilterPlugins = tt.skippedPlugins
|
||||
gotStatus := f.RunFilterPlugins(ctx, state, pod, nil)
|
||||
if diff := cmp.Diff(gotStatus, tt.wantStatus, cmpOpts...); diff != "" {
|
||||
t.Errorf("Unexpected status: (-got, +want):\n%s", diff)
|
||||
if diff := cmp.Diff(tt.wantStatus, gotStatus, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Unexpected status: (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2262,8 +2264,9 @@ func TestPostFilterPlugins(t *testing.T) {
|
||||
_ = f.Close()
|
||||
}()
|
||||
_, gotStatus := f.RunPostFilterPlugins(ctx, nil, pod, nil)
|
||||
if !reflect.DeepEqual(gotStatus, tt.wantStatus) {
|
||||
t.Errorf("Unexpected status. got: %v, want: %v", gotStatus, tt.wantStatus)
|
||||
|
||||
if diff := cmp.Diff(tt.wantStatus, gotStatus, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Unexpected status (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2430,8 +2433,8 @@ func TestFilterPluginsWithNominatedPods(t *testing.T) {
|
||||
}()
|
||||
tt.nodeInfo.SetNode(tt.node)
|
||||
gotStatus := f.RunFilterPluginsWithNominatedPods(ctx, framework.NewCycleState(), tt.pod, tt.nodeInfo)
|
||||
if diff := cmp.Diff(gotStatus, tt.wantStatus, cmpOpts...); diff != "" {
|
||||
t.Errorf("Unexpected status: (-got, +want):\n%s", diff)
|
||||
if diff := cmp.Diff(tt.wantStatus, gotStatus, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Unexpected status: (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2592,8 +2595,8 @@ func TestPreBindPlugins(t *testing.T) {
|
||||
|
||||
status := f.RunPreBindPlugins(ctx, nil, pod, "")
|
||||
|
||||
if !reflect.DeepEqual(status, tt.wantStatus) {
|
||||
t.Errorf("wrong status code. got %v, want %v", status, tt.wantStatus)
|
||||
if diff := cmp.Diff(tt.wantStatus, status, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Wrong status code (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2754,8 +2757,8 @@ func TestReservePlugins(t *testing.T) {
|
||||
|
||||
status := f.RunReservePluginsReserve(ctx, nil, pod, "")
|
||||
|
||||
if !reflect.DeepEqual(status, tt.wantStatus) {
|
||||
t.Errorf("wrong status code. got %v, want %v", status, tt.wantStatus)
|
||||
if diff := cmp.Diff(tt.wantStatus, status, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Wrong status code (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2885,8 +2888,8 @@ func TestPermitPlugins(t *testing.T) {
|
||||
}
|
||||
|
||||
status := f.RunPermitPlugins(ctx, nil, pod, "")
|
||||
if !reflect.DeepEqual(status, tt.want) {
|
||||
t.Errorf("wrong status code. got %v, want %v", status, tt.want)
|
||||
if diff := cmp.Diff(tt.want, status, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Wrong status code (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -3320,8 +3323,8 @@ func TestWaitOnPermit(t *testing.T) {
|
||||
go tt.action(f)
|
||||
|
||||
got := f.WaitOnPermit(ctx, pod)
|
||||
if !reflect.DeepEqual(tt.want, got) {
|
||||
t.Errorf("Unexpected status: want %v, but got %v", tt.want, got)
|
||||
if diff := cmp.Diff(tt.want, got, statusCmpOpts...); diff != "" {
|
||||
t.Errorf("Unexpected status (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -3369,7 +3372,7 @@ func TestListPlugins(t *testing.T) {
|
||||
}()
|
||||
got := f.ListPlugins()
|
||||
if diff := cmp.Diff(tt.want, got); diff != "" {
|
||||
t.Errorf("unexpected plugins (-want,+got):\n%s", diff)
|
||||
t.Errorf("Unexpected plugins (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user