forked from coreos/coretest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_test.go
153 lines (137 loc) · 3.09 KB
/
core_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package coretest
import (
"os"
"os/exec"
"path"
"testing"
"time"
)
const (
CaPath = "/usr/share/coreos-ca-certificates/"
CmdTimeout = time.Second * 3
DbusTimeout = time.Second * 20
HttpTimeout = time.Second * 3
PortTimeout = time.Second * 3
UpdateEnginePubKey = "/usr/share/update_engine/update-payload-key.pub.pem"
UpdateEnginePubKeySha256 = "d410d94dc56a1cba8df71c94ea6925811e44b09416f66958ab7a453f0731d80e"
UpdateUrl = "https://api.core-os.net/v1/update/"
)
func TestPortSsh(t *testing.T) {
t.Parallel()
err := CheckPort("tcp", "127.0.0.1:22", PortTimeout)
if err != nil {
t.Fatal(err)
}
}
func TestUpdateEngine(t *testing.T) {
t.Parallel()
errc := make(chan error, 1)
go func() {
c := exec.Command("update_engine_client", "-omaha_url", UpdateUrl)
err := c.Run()
errc <- err
}()
select {
case <-time.After(CmdTimeout):
t.Fatalf("update_engine_client timed out after %s.", CmdTimeout)
case err := <-errc:
if err != nil {
t.Error(err)
}
}
err := CheckDbusInterface("org.chromium.UpdateEngineInterface", DbusTimeout)
if err != nil {
t.Fatal(err)
}
}
func TestDockerEcho(t *testing.T) {
t.Parallel()
errc := make(chan error, 1)
go func() {
c := exec.Command("docker", "run", "busybox", "echo")
err := c.Run()
errc <- err
}()
select {
case <-time.After(CmdTimeout):
t.Fatalf("DockerEcho timed out after %s.", CmdTimeout)
case err := <-errc:
if err != nil {
t.Error(err)
}
}
}
func TestUpdateServiceHttp(t *testing.T) {
t.Parallel()
err := CheckHttpStatus("http://api.core-os.net/v1/c10n/group", HttpTimeout)
if err != nil {
t.Error(err)
}
}
func TestSymlinkResolvConf(t *testing.T) {
t.Parallel()
f, err := os.Lstat("/etc/resolv.conf")
if err != nil {
t.Fatal(err)
}
if !IsLink(f) {
t.Fatal("/etc/resolv.conf is not a symlink.")
}
}
func TestInstalledCACerts(t *testing.T) {
t.Parallel()
caCerts := []string{
"CoreOS_Internet_Authority.pem",
"CoreOS_Network_Authority.pem",
}
for _, fileName := range caCerts {
_, err := os.Stat(path.Join(CaPath, fileName))
if err != nil {
t.Error(err)
}
}
}
func TestInstalledUpdateEngineRsaKeys(t *testing.T) {
t.Parallel()
fileHash, err := Sha256File(UpdateEnginePubKey)
if err != nil {
t.Fatal(err)
}
if string(fileHash) != UpdateEnginePubKeySha256 {
t.Fatalf("%s:%s does not match hash %s.", UpdateEnginePubKey, fileHash,
UpdateEnginePubKeySha256)
}
}
func TestServicesActive(t *testing.T) {
t.Parallel()
units := []string{
"update-engine.service",
"docker.service",
"default.target",
}
for _, unit := range units {
c := exec.Command("systemctl", "is-active", unit)
err := c.Run()
if err != nil {
t.Error(err)
}
}
}
func TestReadOnlyFs(t *testing.T) {
mountModes := make(map[string]bool)
mounts, err := GetMountTable()
if err != nil {
t.Fatal(err)
}
for _, m := range mounts {
mountModes[m.MountPoint] = m.Options[0] == "ro"
}
if mp, ok := mountModes["/"]; ok {
if mp {
return
} else {
t.Fatalf("/ is not mounted ro.")
}
}
t.Fatal("could not find rootfs.")
}