infrastructure/nixos-modules/cloud/test.py
Raphael Borun Das Gupta a76519ac01
Some checks failed
CI / build (push) Failing after 19m20s
CI / deploy (docs-ops.qo.is) (push) Has been skipped
CI / deploy (system-physical) (push) Has been skipped
CI / deploy (system-vm) (push) Has been skipped
qois.cloud: add basic test (WIP)
2025-06-21 10:26:17 +02:00

34 lines
1.3 KiB
Python

def test(subtest, webserver):
webserver.wait_for_unit("nginx")
webserver.wait_for_open_port(80)
webserver.wait_for_unit("nextcloud-setup.service")
webserver.wait_for_unit("phpfpm-nextcloud.service")
# Helpers
def curl_variable_test(node, variable, expected, url):
value = node.succeed(
f"curl -s --no-location -o /dev/null -w '%{{{variable}}}' '{url}'"
)
assert value == expected, (
f"expected {variable} to be '{expected}' but got '{value}'"
)
def expect_http_code(node, code, url):
curl_variable_test(node, "http_code", code, url)
def expect_http_content_contains(node, expectedContentSnippet, url):
content = node.succeed(f"curl --no-location --silent '{url}'")
assert expectedContentSnippet in content, f"""
expected in content:
{expectedContentSnippet}
at {url} but got following content:
{content}
"""
# Tests
with subtest("website is successfully served on cloud.example.com"):
webserver.succeed("grep cloud.example.com /etc/hosts")
expect_http_code(webserver, "200", "http://cloud.example.com")
expect_http_content_contains(
webserver, "Log in to cloud.qoo.is", "http://docs.example.com"
)