Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit a11d017

Browse files
author
Dongsu Park
authored
Merge pull request #1693 from endocode/dongsu/unit-test-rootuser-systemd
registry/rpc: re-enable error handling after NewSystemdUnitManage
2 parents 686bddf + c86e6d0 commit a11d017

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

registry/rpc/registrymux_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package rpc
1717
import (
1818
"io/ioutil"
1919
"os"
20+
"syscall"
2021
"testing"
2122

2223
etcd "github.com/coreos/etcd/client"
@@ -89,19 +90,21 @@ func TestRegistryMuxUnitManagement(t *testing.T) {
8990
}
9091
defer os.RemoveAll(uDir)
9192

93+
if syscall.Geteuid() != 0 {
94+
t.Skipf("non-root user cannot call systemd unit manager. skip.")
95+
}
96+
if info, err := os.Stat("/run/systemd/system"); err != nil || !info.IsDir() {
97+
t.Skipf("systemd is not available. skip.")
98+
}
99+
92100
state := &machine.MachineState{
93101
ID: "id",
94102
PublicIP: "127.0.0.1",
95103
Metadata: make(map[string]string, 0),
96104
}
97105
mgr, err := systemd.NewSystemdUnitManager(uDir, false)
98106
if err != nil {
99-
// NOTE: ideally we should fail with t.Fatalf(), but then it would always
100-
// fail on travis CI, because apparently systemd dbus socket is not
101-
// available there. So let's just skip the test for now.
102-
// In the long run, we should find a way to test it correctly on travis.
103-
// - dpark 20160812
104-
t.Skipf("unexpected error creating systemd unit manager: %v", err)
107+
t.Fatalf("unexpected error creating systemd unit manager: %v", err)
105108
}
106109

107110
mach := machine.NewCoreOSMachine(*state, mgr)

ssh/known_hosts_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io/ioutil"
2020
"net"
2121
"os"
22+
"runtime"
2223
"strconv"
2324
"syscall"
2425
"testing"
@@ -165,7 +166,13 @@ func TestWrongHostKeyFile(t *testing.T) {
165166
// If run as root, drop privileges temporarily
166167
if id := syscall.Geteuid(); id == 0 {
167168
if err := syscall.Setuid(12345); err != nil {
168-
t.Fatalf("error setting uid: %v", err)
169+
if runtime.GOOS == "linux" {
170+
// On Linux syscall.Setuid is not supported, so we should not fail
171+
// the test, but just skip for now. - dpark 20161021
172+
t.Skipf("error setting uid: %v", err)
173+
} else {
174+
t.Fatalf("error setting uid: %v", err)
175+
}
169176
}
170177
defer syscall.Setuid(id)
171178
}

0 commit comments

Comments
 (0)