From e78af6b0e84a6c1818b75538ac352615388a15ea Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 1 Jun 2017 20:11:50 -0700 Subject: [PATCH] dhcp4: only run the linuxConn tests on linux. Seems obvious when you say it like that! Fixes #41. --- dhcp4/conn_linux_test.go | 46 ++++++++++++++++++++++++++++++++++++++++ dhcp4/conn_test.go | 24 --------------------- 2 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 dhcp4/conn_linux_test.go diff --git a/dhcp4/conn_linux_test.go b/dhcp4/conn_linux_test.go new file mode 100644 index 0000000..020d6a0 --- /dev/null +++ b/dhcp4/conn_linux_test.go @@ -0,0 +1,46 @@ +// Copyright 2016 Google Inc. +// +// 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. + +//+build linux + +package dhcp4 + +import ( + "net" + "os" + "runtime" + "testing" +) + +func TestLinuxConn(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skipf("not supported on %s", runtime.GOOS) + } + if os.Getuid() != 0 { + t.Skipf("must be root on %s", runtime.GOOS) + } + + // Use a listener to grab a free port, but we don't use it beyond + // that. + l, err := net.ListenPacket("udp4", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + c, err := newLinuxConn(l.LocalAddr().(*net.UDPAddr).Port) + if err != nil { + t.Fatalf("creating the linuxconn: %s", err) + } + + testConn(t, c, l.LocalAddr().String()) +} diff --git a/dhcp4/conn_test.go b/dhcp4/conn_test.go index f98fe22..2bce235 100644 --- a/dhcp4/conn_test.go +++ b/dhcp4/conn_test.go @@ -16,9 +16,7 @@ package dhcp4 import ( "net" - "os" "reflect" - "runtime" "testing" "time" ) @@ -132,25 +130,3 @@ func TestPortableConn(t *testing.T) { testConn(t, c, addr) } - -func TestLinuxConn(t *testing.T) { - if runtime.GOOS != "linux" { - t.Skipf("not supported on %s", runtime.GOOS) - } - if os.Getuid() != 0 { - t.Skipf("must be root on %s", runtime.GOOS) - } - - // Use a listener to grab a free port, but we don't use it beyond - // that. - l, err := net.ListenPacket("udp4", "127.0.0.1:0") - if err != nil { - t.Fatal(err) - } - c, err := newLinuxConn(l.LocalAddr().(*net.UDPAddr).Port) - if err != nil { - t.Fatalf("creating the linuxconn: %s", err) - } - - testConn(t, c, l.LocalAddr().String()) -}