@@ -1,13 +1,5 @@
1−{ system ? builtins.currentSystem
2−, config ? {}
3−, pkgs ? import ../.. { inherit system config; }
4−}:
5−
61let
7− inherit (import ../lib/testing.nix { inherit system pkgs; }) makeTest;
8−in
9−map (
10− backend: makeTest {
2+ f = backend: import ./make-test-python.nix ({ pkgs, ... }: {
113 name = "ihatemoney-${backend}";
124 machine = { lib, ... }: {
135 services.ihatemoney = {
@@ -30,23 +22,34 @@ map (
3022 };
3123 };
3224 testScript = ''
33− $machine->waitForOpenPort(8000);
34− $machine->waitForUnit("uwsgi.service");
35− my $return = $machine->succeed("curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay\@example.com'");
36− die "wrong project id $return" unless "\"yay\"\n" eq $return;
37− my $timestamp = $machine->succeed("stat --printf %Y /var/lib/ihatemoney/secret_key");
38− my $owner = $machine->succeed("stat --printf %U:%G /var/lib/ihatemoney/secret_key");
39− die "wrong ownership for the secret key: $owner, is uwsgi running as the right user ?" unless $owner eq "ihatemoney:ihatemoney";
40− $machine->shutdown();
41− $machine->start();
42− $machine->waitForOpenPort(8000);
43− $machine->waitForUnit("uwsgi.service");
44− # check that the database is really persistent
45− print $machine->succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay");
46− # check that the secret key is really persistent
47− my $timestamp2 = $machine->succeed("stat --printf %Y /var/lib/ihatemoney/secret_key");
48− die unless $timestamp eq $timestamp2;
49− $machine->succeed("curl http://localhost:8000 | grep ihatemoney");
25+ machine.wait_for_open_port(8000)
26+ machine.wait_for_unit("uwsgi.service")
27+
28+ assert '"yay"' in machine.succeed(
29+ "curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay\@example.com'"
30+ )
31+ owner, timestamp = machine.succeed(
32+ "stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
33+ ).split("___")
34+ assert "ihatemoney:ihatemoney" == owner
35+
36+ with subtest("Restart machine and service"):
37+ machine.shutdown()
38+ machine.start()
39+ machine.wait_for_open_port(8000)
40+ machine.wait_for_unit("uwsgi.service")
41+
42+ with subtest("check that the database is really persistent"):
43+ machine.succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay")
44+
45+ with subtest("check that the secret key is really persistent"):
46+ timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
47+ assert timestamp == timestamp2
48+
49+ assert "ihatemoney" in machine.succeed("curl http://localhost:8000")
5050 '';
51− }
52−) [ "sqlite" "postgresql" ]
51+ });
52+in {
53+ ihatemoney-sqlite = f "sqlite";
54+ ihatemoney-postgresql = f "postgresql";
55+}