Merge pull request #112799 from kerthcet/cleanup/strategy-test

optimize testcases arrangement
This commit is contained in:
Kubernetes Prow Robot 2022-12-09 15:43:29 -08:00 committed by GitHub
commit 4106b10d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1137,13 +1137,16 @@ func newPodWithHugePageValue(resourceName api.ResourceName, value resource.Quant
func TestPodStrategyValidate(t *testing.T) {
const containerName = "container"
errTest := []struct {
name string
pod *api.Pod
tests := []struct {
name string
pod *api.Pod
wantErr bool
}{
{
name: "a new pod setting container with indivisible hugepages values",
pod: newPodWithHugePageValue(api.ResourceHugePagesPrefix+"1Mi", resource.MustParse("1.1Mi")),
name: "a new pod setting container with indivisible hugepages values",
pod: newPodWithHugePageValue(api.ResourceHugePagesPrefix+"1Mi", resource.MustParse("1.1Mi")),
wantErr: true,
},
{
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",
@ -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",
pod: &api.Pod{
@ -1260,8 +1251,12 @@ func TestPodStrategyValidate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if errs := Strategy.Validate(genericapirequest.NewContext(), tc.pod); len(errs) != 0 {
t.Errorf("unexpected error:%v", errs)
errs := Strategy.Validate(genericapirequest.NewContext(), tc.pod)
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())
}
})
}