Repository navigation
Expand file tree
/
Copy pathembed_test.go
More file actions
62 lines (59 loc) · 1.73 KB
/
Copy pathembed_test.go
File metadata and controls
62 lines (59 loc) · 1.73 KB
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
package pullgate
import (
"os"
"regexp"
"slices"
"strings"
"testing"
)
// TestEnableIsTheReadme: Enable, which pullgate update re-enables after an
// update, is the list of units of the README "start" block.
func TestEnableIsTheReadme(t *testing.T) {
b, err := os.ReadFile("README.md")
if err != nil {
t.Fatal(err)
}
_, block, ok := strings.Cut(string(b), "<!-- install-test:start -->\n```sh\n")
if !ok {
t.Fatal("README.md has no install-test:start block")
}
block, _, _ = strings.Cut(block, "```")
re := regexp.MustCompile(`pullgate-[a-z-]+(@NAME)?\.(service|timer|path)`)
var got []string
for line := range strings.SplitSeq(block, "\n") {
line, _, _ = strings.Cut(line, "#")
got = append(got, re.FindAllString(line, -1)...)
}
slices.Sort(got)
want := slices.Clone(Enable)
slices.Sort(want)
if !slices.Equal(got, want) {
t.Fatalf("the README start block enables %q, Enable is %q. Fix: change both together", got, want)
}
units := Units()
for _, e := range Enable {
if _, ok := units[strings.Replace(e, "@NAME.", "@.", 1)]; !ok {
t.Errorf("%s: no unit file in contrib/systemd", e)
}
}
}
// TestUnitsAreEmbedded: the binary carries every file of contrib/systemd.
func TestUnitsAreEmbedded(t *testing.T) {
entries, err := os.ReadDir("contrib/systemd")
if err != nil {
t.Fatal(err)
}
units := Units()
if len(units) != len(entries) {
t.Fatalf("embedded %d units, contrib/systemd has %d files", len(units), len(entries))
}
for _, e := range entries {
b, _ := os.ReadFile("contrib/systemd/" + e.Name())
if units[e.Name()] != string(b) {
t.Errorf("%s: the embedded copy differs", e.Name())
}
}
if b, _ := os.ReadFile("install.sh"); InstallScript != string(b) {
t.Error("the embedded install.sh differs")
}
}