author | Alberto Bertogli
<albertito@blitiri.com.ar> 2020-05-28 23:46:02 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2020-05-28 23:49:11 UTC |
parent | 148d44400ed0f51ea5a124acc78485b1fdae93e0 |
.travis.yml | +1 | -1 |
systemd_test.go | +32 | -29 |
diff --git a/.travis.yml b/.travis.yml index 3dfb220..b1332d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ dist: bionic go_import_path: blitiri.com.ar/go/systemd go: - - 1.7 + - 1.9 - stable - master diff --git a/systemd_test.go b/systemd_test.go index 3c9099c..6ef6d6a 100644 --- a/systemd_test.go +++ b/systemd_test.go @@ -10,6 +10,7 @@ import ( "testing" ) +// setenv prepares the environment and resets the internal state. func setenv(pid, fds string, names ...string) { os.Setenv("LISTEN_PID", pid) os.Setenv("LISTEN_FDS", fds) @@ -20,6 +21,37 @@ func setenv(pid, fds string, names ...string) { listenError = nil } +// newListener creates a TCP listener. +func newListener(t *testing.T) *net.TCPListener { + t.Helper() + addr := &net.TCPAddr{ + Port: 0, + } + + l, err := net.ListenTCP("tcp", addr) + if err != nil { + t.Fatalf("Could not create TCP listener: %v", err) + } + + return l +} + +// listenerFd returns a file descriptor for the listener. +// Note it is a NEW file descriptor, not the original one. +func listenerFd(t *testing.T, l *net.TCPListener) int { + t.Helper() + f, err := l.File() + if err != nil { + t.Fatalf("Could not get TCP listener file: %v", err) + } + + return int(f.Fd()) +} + +func sameAddr(a, b net.Addr) bool { + return a.Network() == b.Network() && a.String() == b.String() +} + func TestEmptyEnvironment(t *testing.T) { cases := []struct{ pid, fds string }{ {"", ""}, @@ -146,35 +178,6 @@ func TestBadFDs(t *testing.T) { } } -// newListener creates a TCP listener. -func newListener(t *testing.T) *net.TCPListener { - addr := &net.TCPAddr{ - Port: 0, - } - - l, err := net.ListenTCP("tcp", addr) - if err != nil { - t.Fatalf("Could not create TCP listener: %v", err) - } - - return l -} - -// listenerFd returns a file descriptor for the listener. -// Note it is a NEW file descriptor, not the original one. -func listenerFd(t *testing.T, l *net.TCPListener) int { - f, err := l.File() - if err != nil { - t.Fatalf("Could not get TCP listener file: %v", err) - } - - return int(f.Fd()) -} - -func sameAddr(a, b net.Addr) bool { - return a.Network() == b.Network() && a.String() == b.String() -} - func TestOneSocket(t *testing.T) { l := newListener(t) defer l.Close()