mirror of https://github.com/perkeep/perkeep.git
netutil: return ErrUnsupportedOS and skip tests if not darwin or linux
Change-Id: I50235b0112668a50776043708e9bb8eb13131900
This commit is contained in:
parent
82bb3b71ca
commit
b6a688ba8a
|
@ -34,7 +34,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ErrNotFound = errors.New("netutil: connection not found")
|
||||
var (
|
||||
ErrNotFound = errors.New("netutil: connection not found")
|
||||
ErrUnsupportedOS = errors.New("netutil: not implemented on this operating system")
|
||||
)
|
||||
|
||||
// ConnUserid returns the uid that owns the given localhost connection.
|
||||
// The returned error is ErrNotFound if the connection wasn't found.
|
||||
|
@ -84,17 +87,19 @@ func AddrPairUserid(local, remote net.Addr) (uid int, err error) {
|
|||
if runtime.GOOS == "darwin" {
|
||||
return uidFromDarwinLsof(lAddr.IP, lAddr.Port, rAddr.IP, rAddr.Port)
|
||||
}
|
||||
|
||||
file := "/proc/net/tcp"
|
||||
if !localv4 {
|
||||
file = "/proc/net/tcp6"
|
||||
if runtime.GOOS == "linux" {
|
||||
file := "/proc/net/tcp"
|
||||
if !localv4 {
|
||||
file = "/proc/net/tcp6"
|
||||
}
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("Error opening %s: %v", file, err)
|
||||
}
|
||||
defer f.Close()
|
||||
return uidFromReader(lAddr.IP, lAddr.Port, rAddr.IP, rAddr.Port, f)
|
||||
}
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("Error opening %s: %v", file, err)
|
||||
}
|
||||
defer f.Close()
|
||||
return uidFromReader(lAddr.IP, lAddr.Port, rAddr.IP, rAddr.Port, f)
|
||||
return 0, ErrUnsupportedOS
|
||||
}
|
||||
|
||||
func toLinuxIPv4Order(b []byte) []byte {
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -81,6 +82,9 @@ func testLocalListener(t *testing.T, ln net.Listener) {
|
|||
select {
|
||||
case r := <-c:
|
||||
if r.err != nil {
|
||||
if r.err == ErrUnsupportedOS {
|
||||
t.Skipf("Skipping test; not implemented on " + runtime.GOOS)
|
||||
}
|
||||
t.Fatal(r.err)
|
||||
}
|
||||
if r.uid != os.Getuid() {
|
||||
|
|
Loading…
Reference in New Issue