mirror of
https://github.com/danderson/netboot.git
synced 2025-10-15 17:41:38 +02:00
dhcp4: only run the linuxConn tests on linux.
Seems obvious when you say it like that! Fixes #41.
This commit is contained in:
parent
eb35906ff0
commit
e78af6b0e8
46
dhcp4/conn_linux_test.go
Normal file
46
dhcp4/conn_linux_test.go
Normal file
@ -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())
|
||||||
|
}
|
@ -16,9 +16,7 @@ package dhcp4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -132,25 +130,3 @@ func TestPortableConn(t *testing.T) {
|
|||||||
|
|
||||||
testConn(t, c, addr)
|
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())
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user