From 52e7bf58cf4f0cc61cd3c928e38e2fa7c1015f6b Mon Sep 17 00:00:00 2001 From: mantuliu <240951888@qq.com> Date: Tue, 31 Jan 2023 23:55:09 +0800 Subject: [PATCH] cut avoid unnecessary code duplications Signed-off-by: mantuliu <240951888@qq.com> --- pkg/kubelet/sysctl/allowlist_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/sysctl/allowlist_test.go b/pkg/kubelet/sysctl/allowlist_test.go index cc1a1558317..bbdc30209b0 100644 --- a/pkg/kubelet/sysctl/allowlist_test.go +++ b/pkg/kubelet/sysctl/allowlist_test.go @@ -81,9 +81,7 @@ func TestAllowlist(t *testing.T) { if err := w.validateSysctl(test.sysctl, test.hostNet, test.hostIPC); err != nil { t.Errorf("expected to be allowlisted: %+v, got: %v", test, err) } - pod.Spec.HostNetwork = test.hostNet - 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) if !status.Admit { 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.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) if status.Admit { 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 - pod.Spec.SecurityContext.Sysctls = nil + pod.Spec.SecurityContext.Sysctls = []v1.Sysctl{} status := w.Admit(attrs) if !status.Admit { t.Errorf("expected to be allowlisted,got %+v", status)