mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #112799 from kerthcet/cleanup/strategy-test
optimize testcases arrangement
This commit is contained in:
commit
4106b10d9c
@ -1137,13 +1137,16 @@ func newPodWithHugePageValue(resourceName api.ResourceName, value resource.Quant
|
|||||||
|
|
||||||
func TestPodStrategyValidate(t *testing.T) {
|
func TestPodStrategyValidate(t *testing.T) {
|
||||||
const containerName = "container"
|
const containerName = "container"
|
||||||
errTest := []struct {
|
|
||||||
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
pod *api.Pod
|
pod *api.Pod
|
||||||
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "a new pod setting container with indivisible hugepages values",
|
name: "a new pod setting container with indivisible hugepages values",
|
||||||
pod: newPodWithHugePageValue(api.ResourceHugePagesPrefix+"1Mi", resource.MustParse("1.1Mi")),
|
pod: newPodWithHugePageValue(api.ResourceHugePagesPrefix+"1Mi", resource.MustParse("1.1Mi")),
|
||||||
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "a new pod setting init-container with indivisible hugepages values",
|
name: "a new pod setting init-container with indivisible hugepages values",
|
||||||
@ -1171,6 +1174,7 @@ func TestPodStrategyValidate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "a new pod setting init-container with indivisible hugepages values while container with divisible hugepages values",
|
name: "a new pod setting init-container with indivisible hugepages values while container with divisible hugepages values",
|
||||||
@ -1212,21 +1216,8 @@ func TestPodStrategyValidate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
wantErr: true,
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range errTest {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
if errs := Strategy.Validate(genericapirequest.NewContext(), tc.pod); len(errs) == 0 {
|
|
||||||
t.Error("expected failure")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
pod *api.Pod
|
|
||||||
}{
|
|
||||||
{
|
{
|
||||||
name: "a new pod setting container with divisible hugepages values",
|
name: "a new pod setting container with divisible hugepages values",
|
||||||
pod: &api.Pod{
|
pod: &api.Pod{
|
||||||
@ -1260,8 +1251,12 @@ func TestPodStrategyValidate(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
if errs := Strategy.Validate(genericapirequest.NewContext(), tc.pod); len(errs) != 0 {
|
errs := Strategy.Validate(genericapirequest.NewContext(), tc.pod)
|
||||||
t.Errorf("unexpected error:%v", errs)
|
if tc.wantErr && len(errs) == 0 {
|
||||||
|
t.Errorf("expected errors but got none")
|
||||||
|
}
|
||||||
|
if !tc.wantErr && len(errs) != 0 {
|
||||||
|
t.Errorf("unexpected errors: %v", errs.ToAggregate())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user