diff --git a/pkg/backend/route_network_test.go b/pkg/backend/route_network_test.go index a7fff3c9c0..e1325074c0 100644 --- a/pkg/backend/route_network_test.go +++ b/pkg/backend/route_network_test.go @@ -22,13 +22,10 @@ import ( "github.com/flannel-io/flannel/pkg/ip" "github.com/flannel-io/flannel/pkg/lease" - "github.com/flannel-io/flannel/pkg/ns" "github.com/vishvananda/netlink" ) func TestRouteCache(t *testing.T) { - teardown := ns.SetUpNetlinkTest(t) - defer teardown() lo, err := netlink.LinkByName("lo") if err != nil { @@ -79,8 +76,6 @@ func TestRouteCache(t *testing.T) { } func TestV6RouteCache(t *testing.T) { - teardown := ns.SetUpNetlinkTest(t) - defer teardown() la := netlink.NewLinkAttrs() la.Name = "br" diff --git a/pkg/ip/iface_test.go b/pkg/ip/iface_test.go index 804e117d04..5228c01fcc 100644 --- a/pkg/ip/iface_test.go +++ b/pkg/ip/iface_test.go @@ -21,13 +21,10 @@ import ( "net" "testing" - "github.com/flannel-io/flannel/pkg/ns" "github.com/vishvananda/netlink" ) func TestEnsureV4AddressOnLink(t *testing.T) { - teardown := ns.SetUpNetlinkTest(t) - defer teardown() lo, err := netlink.LinkByName("lo") if err != nil { t.Fatal(err) @@ -65,8 +62,6 @@ func TestEnsureV4AddressOnLink(t *testing.T) { } func TestEnsureV6AddressOnLink(t *testing.T) { - teardown := ns.SetUpNetlinkTest(t) - defer teardown() lo, err := netlink.LinkByName("lo") if err != nil { t.Fatal(err) diff --git a/pkg/ns/ns.go b/pkg/ns/ns.go index 4a96243966..acfce2c6a1 100644 --- a/pkg/ns/ns.go +++ b/pkg/ns/ns.go @@ -16,26 +16,3 @@ // limitations under the License. package ns - -import ( - "runtime" - "testing" - - "github.com/vishvananda/netns" -) - -func SetUpNetlinkTest(t *testing.T) func() { - // new temporary namespace so we don't pollute the host - // lock thread since the namespace is thread local - runtime.LockOSThread() - var err error - ns, err := netns.New() - if err != nil { - t.Fatalf("Failed to create newns: %v", err) - } - - return func() { - ns.Close() - runtime.UnlockOSThread() - } -} diff --git a/pkg/ns/ns_test.go b/pkg/ns/ns_test.go new file mode 100644 index 0000000000..911642139d --- /dev/null +++ b/pkg/ns/ns_test.go @@ -0,0 +1,40 @@ +//go:build !windows +// +build !windows + +// Copyright 2017 flannel authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ns + +import ( + "runtime" + "testing" + + "github.com/vishvananda/netns" +) + +func TestSetUpNetlink(t *testing.T) { + // new temporary namespace so we don't pollute the host + // lock thread since the namespace is thread local + runtime.LockOSThread() + var err error + ns, err := netns.New() + if err != nil { + t.Fatalf("Failed to create newns: %v", err) + } + + defer ns.Close() + defer runtime.UnlockOSThread() + +}