Merge pull request #100883 from xychu/add-lessthan-ut

Add tests for LessThanOrEqual

Kubernetes-commit: 3b7e8da6699e61a255a1729dc408efd9f30a97a4
This commit is contained in:
Kubernetes Publisher 2022-01-31 18:07:52 -08:00
commit 0b7780f8b1
3 changed files with 43 additions and 4 deletions

4
go.mod
View File

@ -44,7 +44,7 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/square/go-jose.v2 v2.2.2
k8s.io/api v0.0.0-20220126052120-b2d630a65cb2
k8s.io/apimachinery v0.0.0-20220125200954-322368c20f9b
k8s.io/apimachinery v0.0.0-20220129104801-df993592a122
k8s.io/client-go v0.0.0-20220125012153-7f0455096073
k8s.io/component-base v0.0.0-20220122012704-f57281d7c18f
k8s.io/klog/v2 v2.40.1
@ -58,7 +58,7 @@ require (
replace (
k8s.io/api => k8s.io/api v0.0.0-20220126052120-b2d630a65cb2
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220125200954-322368c20f9b
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220129104801-df993592a122
k8s.io/client-go => k8s.io/client-go v0.0.0-20220125012153-7f0455096073
k8s.io/component-base => k8s.io/component-base v0.0.0-20220122012704-f57281d7c18f
)

4
go.sum
View File

@ -958,8 +958,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20220126052120-b2d630a65cb2 h1:24pR4NHIBxlpFXgBCm8IN5bmu99X4gYfH7lDLUAsK0A=
k8s.io/api v0.0.0-20220126052120-b2d630a65cb2/go.mod h1:dNpXx9aCJUTKbIJ8TuZJwjNPhWcvlxnQMlXNzlbWdfE=
k8s.io/apimachinery v0.0.0-20220125200954-322368c20f9b h1:b6hngIfatKOyoqX9X5TqJ/UJdLsEOSdCogU69QC0hn4=
k8s.io/apimachinery v0.0.0-20220125200954-322368c20f9b/go.mod h1:x0yrIIAdS2/JR9TKFHtSn8dYQDIw8mTIeAqPvOuEozA=
k8s.io/apimachinery v0.0.0-20220129104801-df993592a122 h1:14bzAwJDW8S86wqAvH5sVjI1ilnCWnAKWXomMStJ3Yo=
k8s.io/apimachinery v0.0.0-20220129104801-df993592a122/go.mod h1:x0yrIIAdS2/JR9TKFHtSn8dYQDIw8mTIeAqPvOuEozA=
k8s.io/client-go v0.0.0-20220125012153-7f0455096073 h1:wf08facRQq6h3c4yF49Y50yHNXhyhcBZ3Ih2ZadPAOo=
k8s.io/client-go v0.0.0-20220125012153-7f0455096073/go.mod h1:LNxsq+SALfG518PchpbdMDqd4XMon0C1Wlnu0AJg8/w=
k8s.io/component-base v0.0.0-20220122012704-f57281d7c18f h1:w7E6jE+nZJ8H9L+kKxRu/MR1FPmwaG25AtoqHj2QG6w=

View File

@ -77,6 +77,45 @@ func TestEquals(t *testing.T) {
}
}
func TestLessThanOrEqual(t *testing.T) {
testCases := map[string]struct {
a corev1.ResourceList
b corev1.ResourceList
expected bool
out []corev1.ResourceName
}{
"isEmpty": {
a: corev1.ResourceList{},
b: corev1.ResourceList{},
expected: true,
out: []corev1.ResourceName{},
},
"isEqual": {
a: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")},
b: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")},
expected: true,
out: []corev1.ResourceName{},
},
"isLessThan": {
a: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")},
b: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("200m")},
expected: true,
out: []corev1.ResourceName{},
},
"isGreaterThan": {
a: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("200m")},
b: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")},
expected: false,
out: []corev1.ResourceName{corev1.ResourceCPU},
},
}
for testName, testCase := range testCases {
if result, out := LessThanOrEqual(testCase.a, testCase.b); result != testCase.expected && !reflect.DeepEqual(out, testCase.out) {
t.Errorf("%s expected: %v/%v, actual: %v/%v", testName, testCase.expected, testCase.out, result, out)
}
}
}
func TestMax(t *testing.T) {
testCases := map[string]struct {
a corev1.ResourceList