Download this file
| 1 | //go:build linux && rootrunner |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func plan14MaterializedDependencies(t *testing.T, ctl func(context.Context, ...string) (string, error)) { |
| 13 | t.Helper() |
| 14 | units := []struct{ name, body string }{ |
| 15 | {"carlos-edge.service", "[Service]\nType=simple\nExecStart=/bin/sleep infinity\n"}, |
| 16 | {"data-instances.mount", "[Mount]\nWhat=/data/instances\nWhere=/data/instances\nType=none\nOptions=bind,nosymfollow\n"}, |
| 17 | {"run-carlos-instances.mount", "[Mount]\nWhat=/run/carlos/instances\nWhere=/run/carlos/instances\nType=none\nOptions=bind,nosymfollow\n"}, |
| 18 | {"run-carlos-logs.mount", "[Mount]\nWhat=/run/carlos/logs\nWhere=/run/carlos/logs\nType=none\nOptions=bind,nosymfollow\n"}, |
| 19 | } |
| 20 | for _, u := range units { |
| 21 | path := filepath.Join("/run/systemd/system", u.name) |
| 22 | f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | if _, err = f.WriteString(u.body); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | f.Close() |
| 30 | t.Cleanup(func() { |
| 31 | ctl(context.Background(), "stop", u.name) |
| 32 | os.Remove(path) |
| 33 | ctl(context.Background(), "daemon-reload") |
| 34 | }) |
| 35 | } |
| 36 | if out, err := ctl(t.Context(), "daemon-reload"); err != nil { |
| 37 | t.Fatal(out, err) |
| 38 | } |
| 39 | } |
| 40 | |