...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package util
16
17 import (
18 "testing"
19 )
20
21 func testIsRunningSystemd(t *testing.T) {
22 if !IsRunningSystemd() {
23 t.Skip("Not running on a systemd host")
24 }
25 }
26
27 func TestRunningFromSystemService(t *testing.T) {
28 testIsRunningSystemd(t)
29 t.Parallel()
30
31
32 s, err := RunningFromSystemService()
33 if err != nil {
34 t.Error(err.Error())
35 } else if s {
36 t.Errorf("tests aren't expected to run as a service")
37 }
38 }
39
40 func TestCurrentUnitName(t *testing.T) {
41 testIsRunningSystemd(t)
42
43 fromService, err := RunningFromSystemService()
44 if err != nil || !fromService {
45 t.Skip("Not running from a systemd service")
46 }
47
48 s, err := CurrentUnitName()
49 if err != nil {
50 t.Error(err.Error())
51 }
52 if s == "" {
53 t.Error("CurrentUnitName returned a empty string")
54 }
55 }
56
57 func TestGetMachineID(t *testing.T) {
58 testIsRunningSystemd(t)
59
60 id, err := GetMachineID()
61 if err != nil {
62 t.Error(err.Error())
63 }
64 if id == "" {
65 t.Error("GetMachineID returned a empty string")
66 }
67 }
68
69 func TestGetRunningSlice(t *testing.T) {
70 testIsRunningSystemd(t)
71
72 s, err := getRunningSlice()
73 if err != nil {
74 t.Error(err.Error())
75 }
76 if s == "" {
77 t.Error("getRunningSlice returned a empty string")
78 }
79 }
80
View as plain text