From 0b10ec44de39e06b7c88c24bb013dadebadab198 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 30 Mar 2018 14:45:25 -0400 Subject: [PATCH] Use a dummy ns.NetNS in sdn_cni_plugin_test.go --- .../sdn-cni-plugin/sdn_cni_plugin_test.go | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/network/sdn-cni-plugin/sdn_cni_plugin_test.go b/pkg/network/sdn-cni-plugin/sdn_cni_plugin_test.go index 607feb82bc98..101acc904fcb 100644 --- a/pkg/network/sdn-cni-plugin/sdn_cni_plugin_test.go +++ b/pkg/network/sdn-cni-plugin/sdn_cni_plugin_test.go @@ -57,6 +57,24 @@ func clearEnv() { } } +type dummyHostNS struct{} + +func (ns *dummyHostNS) Do(toRun func(ns.NetNS) error) error { + return toRun(ns) +} +func (ns *dummyHostNS) Set() error { + panic("should not be reached") +} +func (ns *dummyHostNS) Path() string { + panic("should not be reached") +} +func (ns *dummyHostNS) Fd() uintptr { + panic("should not be reached") +} +func (ns *dummyHostNS) Close() error { + panic("should not be reached") +} + func TestOpenshiftSdnCNIPlugin(t *testing.T) { tmpDir, err := utiltesting.MkTmpdir("cniserver") if err != nil { @@ -70,12 +88,7 @@ func TestOpenshiftSdnCNIPlugin(t *testing.T) { t.Fatalf("error starting CNI server: %v", err) } - hostNS, err := ns.GetCurrentNS() - if err != nil { - panic(fmt.Sprintf("could not get current kernel netns: %v", err)) - } - defer hostNS.Close() - cniPlugin := NewCNIPlugin(path, hostNS) + cniPlugin := NewCNIPlugin(path, &dummyHostNS{}) expectedIP, expectedNet, _ := net.ParseCIDR("10.0.0.2/24") expectedResult = &cni020.Result{