Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh committed Aug 8, 2023
1 parent 88a259d commit a95805a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
48 changes: 21 additions & 27 deletions nix/postgres_test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,26 @@
initialScript.before = "CREATE USER bar;";
initialScript.after = "CREATE DATABASE foo OWNER bar;";
};
services.postgres."pg2" = {
enable = true;
listen_addresses = "127.0.0.1";
port = 5433;
settings.processes.test =
let
cfg = config.services.postgres."pg1";
in
{
disabled = true;
command = pkgs.writeShellApplication {
text = ''
echo 'SELECT version();' | ${cfg.package}/bin/psql -h 127.0.0.1
echo 'SHOW hba_file;' | ${cfg.package}/bin/psql -h 127.0.0.1 | ${pkgs.gawk}/bin/awk 'NR==3' | ${pkgs.gnugrep}/bin/grep '^ /nix/store'
# initialScript.before test
echo "SELECT 1 FROM pg_roles WHERE rolname = 'bar';" | ${cfg.package}/bin/psql -h 127.0.0.1 | ${pkgs.gnugrep}/bin/grep -q 1
# initialScript.after test
echo "SELECT 1 FROM pg_database WHERE datname = 'foo';" | ${cfg.package}/bin/psql -h 127.0.0.1 | ${pkgs.gnugrep}/bin/grep -q 1
'';
name = "postgres-test";
};
depends_on."pg1".condition = "process_healthy";
availability.exit_on_end = true;
};
testScript =
let
cfg = config.services.postgres."pg1";
psql =
"${cfg.package}/bin/psql";
in
''
process_compose.wait_until(lambda procs:
# TODO: Check for 'ready'
procs["pg1"]["status"] == "Running"
)
process_compose.wait_until(lambda procs:
procs["pg2"]["status"] == "Running"
)
machine.succeed("echo 'SELECT version();' | ${psql} -h 127.0.0.1 -U tester")
# Test if `pg2` is listening on the correct port
machine.succeed("echo 'SELECT version();' | ${psql} -h 127.0.0.1 -p 5433 -U tester")
machine.succeed("echo 'SHOW hba_file;' | ${psql} -h 127.0.0.1 -U tester | ${pkgs.gawk}/bin/awk 'NR==3' | ${pkgs.gnugrep}/bin/grep '^ /nix/store'")
# initialScript.before test
machine.succeed("echo \"SELECT 1 FROM pg_roles WHERE rolname = 'bar';\" | ${psql} -h 127.0.0.1 -U tester | grep -q 1")
# initialScript.after test
machine.succeed("echo \"SELECT 1 FROM pg_database WHERE datname = 'foo';\" | ${psql} -h 127.0.0.1 -U tester | grep -q 1")
'';
}
17 changes: 9 additions & 8 deletions test/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
process-compose-flake.url = "github:shivaraj-bh/process-compose-flake/process-as-test";
services-flake.url = "github:juspay/services-flake";
};
outputs = inputs:
Expand Down

0 comments on commit a95805a

Please sign in to comment.