Skip to content

Commit

Permalink
test: use systemctl to get property
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Sep 24, 2024
1 parent 7114b04 commit 4672613
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions nixos-test/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,10 @@ in
};
# https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests
testScript = ''
import re
d = {"docker": docker, "podman": podman}
start_all()
def assert_service_value(service: str, key: str, want: str) -> None:
out = m.succeed(f"systemctl show {service}.service")
pat = r"\b%s=(\S+)$" % key
match = re.search(pat, out, flags=re.M)
if not match:
raise Exception(f"value for \"{key}\" not found in output using pattern \"{pat}\":\n{out}")
got = match.group(1)
assert got == want, f"got: \"{key} = {got}\", want: \"{key} = {want}\""
# Create required directories for Docker Compose volumes and bind mounts.
for runtime, m in d.items():
m.succeed("mkdir -p /mnt/media")
Expand All @@ -86,10 +75,10 @@ in
m.wait_until_succeeds(f"{runtime} inspect service-b | jq .[0].State.Health.Status | grep healthy", timeout=30)
# Ensure that service-b has its restart setting overriden by this test.
assert_service_value(f"{runtime}-service-b", "Restart", "on-success")
m.succeed(f"systemctl show -p Restart {runtime}-service-b.service | grep -E '=on-success$'")
# Ensure that no-restart service has restart disabled.
assert_service_value(f"{runtime}-myproject-no-restart", "Restart", "no")
m.succeed(f"systemctl show -p Restart {runtime}-myproject-no-restart.service | grep -E '=no$'")
# Stop the root unit.
m.systemctl(f"stop {runtime}-compose-myproject-root.target")
Expand Down

0 comments on commit 4672613

Please sign in to comment.