mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-11 12:26:04 +03:00
Process as test (VM -> Native test) (#38)
Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
This commit is contained in:
parent
3a8dcaffcc
commit
72a3eaacc8
17
.github/workflows/ci.yaml
vendored
Normal file
17
.github/workflows/ci.yaml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
name: "CI"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
jobs:
|
||||
checks:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Nix
|
||||
uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: yaxitech/nix-install-pkgs-action@v3
|
||||
with:
|
||||
packages: "nixpkgs#nixci"
|
||||
- run: nixci
|
@ -70,11 +70,11 @@
|
||||
},
|
||||
"process-compose-flake": {
|
||||
"locked": {
|
||||
"lastModified": 1689622628,
|
||||
"narHash": "sha256-V2FEzYpjBYed5Sf6zngbyk7Z0mClxvSu8jawRs0fvRE=",
|
||||
"lastModified": 1692810585,
|
||||
"narHash": "sha256-Zc8nDSVkTUskB5mp9fh1mmOIUvx2pJ5V/Uq/0kxQ6B0=",
|
||||
"owner": "Platonic-Systems",
|
||||
"repo": "process-compose-flake",
|
||||
"rev": "67949a2e1c720838e233d3e7397ccddd7c9d4188",
|
||||
"rev": "2a84a6c2c91c6244e5db8fd46551d5e7f31a85d3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
description = "A demo of sqlite-web";
|
||||
description = "A demo of sqlite-web and multiple postgres services";
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
@ -53,15 +53,16 @@
|
||||
command = pkgs.pgweb;
|
||||
depends_on."pg1".condition = "process_healthy";
|
||||
};
|
||||
|
||||
# Set this attribute and get NixOS VM tests, as a flake check, for free.
|
||||
testScript = ''
|
||||
# FIXME: pgweb is still pending, but only in VM tests for some reason.
|
||||
process_compose.wait_until(lambda procs:
|
||||
procs["pg1"]["status"] == "Running"
|
||||
)
|
||||
machine.succeed("echo 'SELECT version();' | ${config.services.postgres.pg1.package}/bin/psql -h 127.0.0.1 -U tester ${dbName}")
|
||||
'';
|
||||
settings.processes.test = {
|
||||
command = pkgs.writeShellApplication {
|
||||
name = "pg1-test";
|
||||
runtimeInputs = [ config.services.postgres.pg1.package ];
|
||||
text = ''
|
||||
echo 'SELECT version();' | psql -h 127.0.0.1 ${dbName}
|
||||
'';
|
||||
};
|
||||
depends_on."pg1".condition = "process_healthy";
|
||||
};
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
|
4
justfile
4
justfile
@ -8,3 +8,7 @@ ex:
|
||||
# Auto-format the project tree
|
||||
fmt:
|
||||
treefmt
|
||||
|
||||
# Run native tests
|
||||
test:
|
||||
nix flake check test/ --override-input services-flake . -L
|
||||
|
@ -5,32 +5,25 @@
|
||||
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;
|
||||
};
|
||||
testScript =
|
||||
settings.processes.test =
|
||||
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")
|
||||
'';
|
||||
{
|
||||
command = pkgs.writeShellApplication {
|
||||
runtimeInputs = [ cfg.package pkgs.gnugrep ];
|
||||
text = ''
|
||||
echo 'SELECT version();' | psql -h 127.0.0.1
|
||||
echo 'SHOW hba_file;' | psql -h 127.0.0.1 | ${pkgs.gawk}/bin/awk 'NR==3' | grep '^ /nix/store'
|
||||
|
||||
# initialScript.before test
|
||||
echo "SELECT 1 FROM pg_roles WHERE rolname = 'bar';" | psql -h 127.0.0.1 | grep -q 1
|
||||
|
||||
# initialScript.after test
|
||||
echo "SELECT 1 FROM pg_database WHERE datname = 'foo';" | psql -h 127.0.0.1 | grep -q 1
|
||||
'';
|
||||
name = "postgres-test";
|
||||
};
|
||||
depends_on."pg1".condition = "process_healthy";
|
||||
};
|
||||
}
|
||||
|
@ -1,16 +1,24 @@
|
||||
{ config, ... }: {
|
||||
{ pkgs, config, ... }: {
|
||||
services.redis-cluster."c1".enable = true;
|
||||
testScript = ''
|
||||
process_compose.wait_until(lambda procs:
|
||||
# TODO: Check for 'is_ready' of `c1-cluster-create` instead of `c1-n1` (status of `c1-cluster-create` determines whether the hashslots are assigned).
|
||||
# This should be easy after https://github.com/juspay/services-flake/issues/32
|
||||
procs["c1-n1"]["status"] == "Running"
|
||||
)
|
||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30001 ping | grep -q 'PONG'")
|
||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30002 ping | grep -q 'PONG'")
|
||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30003 ping | grep -q 'PONG'")
|
||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30004 ping | grep -q 'PONG'")
|
||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30005 ping | grep -q 'PONG'")
|
||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30006 ping | grep -q 'PONG'")
|
||||
'';
|
||||
|
||||
settings.processes.test =
|
||||
let
|
||||
cfg = config.services.redis-cluster."c1";
|
||||
in
|
||||
{
|
||||
command = pkgs.writeShellApplication {
|
||||
runtimeInputs = [ cfg.package pkgs.gnugrep ];
|
||||
text = ''
|
||||
redis-cli -p 30001 ping | grep -q "PONG"
|
||||
redis-cli -p 30002 ping | grep -q "PONG"
|
||||
redis-cli -p 30003 ping | grep -q "PONG"
|
||||
redis-cli -p 30004 ping | grep -q "PONG"
|
||||
redis-cli -p 30005 ping | grep -q "PONG"
|
||||
redis-cli -p 30006 ping | grep -q "PONG"
|
||||
'';
|
||||
name = "redis-cluster-test";
|
||||
};
|
||||
depends_on."c1-cluster-create".condition = "process_completed";
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
{ config, ... }: {
|
||||
{ pkgs, config, ... }: {
|
||||
services.redis."redis1".enable = true;
|
||||
services.redis."redis2" = {
|
||||
enable = true;
|
||||
port = 6380;
|
||||
};
|
||||
testScript = ''
|
||||
process_compose.wait_until(lambda procs:
|
||||
# TODO: Check for 'is_ready' instead of 'status'
|
||||
procs["redis1"]["status"] == "Running"
|
||||
)
|
||||
process_compose.wait_until(lambda procs:
|
||||
procs["redis2"]["status"] == "Running"
|
||||
)
|
||||
machine.succeed("${config.services.redis.redis1.package}/bin/redis-cli ping | grep -q 'PONG'")
|
||||
machine.succeed("${config.services.redis.redis2.package}/bin/redis-cli -p 6380 ping | grep -q 'PONG'")
|
||||
'';
|
||||
|
||||
settings.processes.test =
|
||||
let
|
||||
cfg = config.services.redis."redis1";
|
||||
in
|
||||
{
|
||||
command = pkgs.writeShellApplication {
|
||||
runtimeInputs = [ cfg.package pkgs.gnugrep ];
|
||||
text = ''
|
||||
redis-cli ping | grep -q "PONG"
|
||||
'';
|
||||
name = "redis-test";
|
||||
};
|
||||
depends_on."redis1".condition = "process_healthy";
|
||||
};
|
||||
}
|
||||
|
@ -20,11 +20,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1686089707,
|
||||
"narHash": "sha256-LTNlJcru2qJ0XhlhG9Acp5KyjB774Pza3tRH0pKIb3o=",
|
||||
"lastModified": 1691464053,
|
||||
"narHash": "sha256-D21ctOBjr2Y3vOFRXKRoFr6uNBvE8q5jC4RrMxRZXTM=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "af21c31b2a1ec5d361ed8050edd0303c31306397",
|
||||
"rev": "844ffa82bbe2a2779c86ab3a72ff1b4176cec467",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@ -54,11 +54,11 @@
|
||||
},
|
||||
"process-compose-flake": {
|
||||
"locked": {
|
||||
"lastModified": 1689622628,
|
||||
"narHash": "sha256-V2FEzYpjBYed5Sf6zngbyk7Z0mClxvSu8jawRs0fvRE=",
|
||||
"lastModified": 1692810585,
|
||||
"narHash": "sha256-Zc8nDSVkTUskB5mp9fh1mmOIUvx2pJ5V/Uq/0kxQ6B0=",
|
||||
"owner": "Platonic-Systems",
|
||||
"repo": "process-compose-flake",
|
||||
"rev": "67949a2e1c720838e233d3e7397ccddd7c9d4188",
|
||||
"rev": "2a84a6c2c91c6244e5db8fd46551d5e7f31a85d3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -15,18 +15,22 @@
|
||||
perSystem = { self', pkgs, lib, ... }: {
|
||||
process-compose = {
|
||||
postgres = {
|
||||
# TODO: remove `port = 0`; as it will be default after this: https://github.com/Platonic-Systems/process-compose-flake/pull/42
|
||||
port = 0;
|
||||
imports = [
|
||||
inputs.services-flake.processComposeModules.default
|
||||
../nix/postgres_test.nix
|
||||
];
|
||||
};
|
||||
redis = {
|
||||
port = 0;
|
||||
imports = [
|
||||
inputs.services-flake.processComposeModules.default
|
||||
../nix/redis_test.nix
|
||||
];
|
||||
};
|
||||
redis-cluster = {
|
||||
port = 0;
|
||||
imports = [
|
||||
inputs.services-flake.processComposeModules.default
|
||||
../nix/redis-cluster_test.nix
|
||||
|
Loading…
Reference in New Issue
Block a user