cut avoid unnecessary code duplications

Signed-off-by: mantuliu <240951888@qq.com>
This commit is contained in:
mantuliu 2023-01-31 23:55:09 +08:00
parent 8ca97dcde1
commit 52e7bf58cf

View File

@ -81,9 +81,7 @@ func TestAllowlist(t *testing.T) {
if err := w.validateSysctl(test.sysctl, test.hostNet, test.hostIPC); err != nil { if err := w.validateSysctl(test.sysctl, test.hostNet, test.hostIPC); err != nil {
t.Errorf("expected to be allowlisted: %+v, got: %v", test, err) t.Errorf("expected to be allowlisted: %+v, got: %v", test, err)
} }
pod.Spec.HostNetwork = test.hostNet pod.Spec.SecurityContext.Sysctls = []v1.Sysctl{{test.sysctl, test.sysctl}}
pod.Spec.HostIPC = test.hostIPC
pod.Spec.SecurityContext.Sysctls = []v1.Sysctl{v1.Sysctl{test.sysctl, test.sysctl}}
status := w.Admit(attrs) status := w.Admit(attrs)
if !status.Admit { if !status.Admit {
t.Errorf("expected to be allowlisted: %+v, got: %+v", test, status) t.Errorf("expected to be allowlisted: %+v, got: %+v", test, status)
@ -96,7 +94,7 @@ func TestAllowlist(t *testing.T) {
} }
pod.Spec.HostNetwork = test.hostNet pod.Spec.HostNetwork = test.hostNet
pod.Spec.HostIPC = test.hostIPC pod.Spec.HostIPC = test.hostIPC
pod.Spec.SecurityContext.Sysctls = []v1.Sysctl{v1.Sysctl{test.sysctl, test.sysctl}} pod.Spec.SecurityContext.Sysctls = []v1.Sysctl{{test.sysctl, test.sysctl}}
status := w.Admit(attrs) status := w.Admit(attrs)
if status.Admit { if status.Admit {
t.Errorf("expected to be rejected: %+v", test) t.Errorf("expected to be rejected: %+v", test)
@ -104,7 +102,7 @@ func TestAllowlist(t *testing.T) {
} }
// test for: len(pod.Spec.SecurityContext.Sysctls) == 0 // test for: len(pod.Spec.SecurityContext.Sysctls) == 0
pod.Spec.SecurityContext.Sysctls = nil pod.Spec.SecurityContext.Sysctls = []v1.Sysctl{}
status := w.Admit(attrs) status := w.Admit(attrs)
if !status.Admit { if !status.Admit {
t.Errorf("expected to be allowlisted,got %+v", status) t.Errorf("expected to be allowlisted,got %+v", status)