From 24a23ed3d7abecaec87a55173f48334c547a8029 Mon Sep 17 00:00:00 2001 From: ibizaman Date: Tue, 14 Mar 2023 23:55:17 -0700 Subject: [PATCH] make keycloak db integration test pass --- tests/integration/keycloak.nix | 20 +++++++++++++------- tests/integration/keycloak/network.nix | 10 +++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/integration/keycloak.nix b/tests/integration/keycloak.nix index 39ca02d..d3bc5da 100644 --- a/tests/integration/keycloak.nix +++ b/tests/integration/keycloak.nix @@ -27,9 +27,6 @@ rec { servicesFile = "tests/integration/keycloak/services.nix"; networkFile = "tests/integration/keycloak/network.nix"; distributionFile = "tests/integration/keycloak/distribution.nix"; - # extraParams = { - # "extra-builtins-file" = ../../extra-builtins.nix; - # }; }; }; @@ -41,11 +38,20 @@ rec { # dysnomiaStateDir = /var/state/dysnomia; testScript = '' - # Wait until the front-end application is deployed - # $test1->waitForFile("/var/tomcat/webapps/testapp"); + def assert_service_started(machine, name): + code, log = machine.systemctl("status " + name) + if code != 0: + raise Exception(name + " could not be started:\n---\n" + log + "---\n") - # Wait a little longer and capture the output of the entry page - # my $result = $test1->mustSucceed("sleep 10; curl --fail http://test2:8080/testapp"); + def assert_database_exists(machine, name): + if machine.succeed("""psql -XtA -U postgres -h localhost -c "SELECT 1 FROM pg_database WHERE datname='{}'" """.format(name)) != '1\n': + raise Exception("could not find database '{}' in postgresql".format(name)) + + with subtest("check postgres service started"): + assert_service_started(test1, "postgresql.service") + + with subtest("check db is created"): + assert_database_exists(test1, "keycloak") ''; }; }; diff --git a/tests/integration/keycloak/network.nix b/tests/integration/keycloak/network.nix index bfba6b5..dcc76a5 100644 --- a/tests/integration/keycloak/network.nix +++ b/tests/integration/keycloak/network.nix @@ -26,11 +26,11 @@ rec { }; }; - # deployment.keys = { - # keycloakinitialadmin.text = '' - # KEYCLOAK_ADMIN_PASSWORD="${builtins.extraBuiltins.pass "keycloak.${domain}/admin"}" - # ''; - # }; + systemd.tmpfiles.rules = [ + # Type Path Mode User Group Age Argument... + ''d /run/keys 0755 root root - -'' + ''f+ /run/keys/keycloackinitialadmin 0755 root root - KEYCLOAK_ADMIN_PASSWORD="KEYCLOAK_ADMIN_PASSWORD"'' + ]; services = { openssh = {