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": {
|
"process-compose-flake": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689622628,
|
"lastModified": 1692810585,
|
||||||
"narHash": "sha256-V2FEzYpjBYed5Sf6zngbyk7Z0mClxvSu8jawRs0fvRE=",
|
"narHash": "sha256-Zc8nDSVkTUskB5mp9fh1mmOIUvx2pJ5V/Uq/0kxQ6B0=",
|
||||||
"owner": "Platonic-Systems",
|
"owner": "Platonic-Systems",
|
||||||
"repo": "process-compose-flake",
|
"repo": "process-compose-flake",
|
||||||
"rev": "67949a2e1c720838e233d3e7397ccddd7c9d4188",
|
"rev": "2a84a6c2c91c6244e5db8fd46551d5e7f31a85d3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
description = "A demo of sqlite-web";
|
description = "A demo of sqlite-web and multiple postgres services";
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
@ -53,15 +53,16 @@
|
|||||||
command = pkgs.pgweb;
|
command = pkgs.pgweb;
|
||||||
depends_on."pg1".condition = "process_healthy";
|
depends_on."pg1".condition = "process_healthy";
|
||||||
};
|
};
|
||||||
|
settings.processes.test = {
|
||||||
# Set this attribute and get NixOS VM tests, as a flake check, for free.
|
command = pkgs.writeShellApplication {
|
||||||
testScript = ''
|
name = "pg1-test";
|
||||||
# FIXME: pgweb is still pending, but only in VM tests for some reason.
|
runtimeInputs = [ config.services.postgres.pg1.package ];
|
||||||
process_compose.wait_until(lambda procs:
|
text = ''
|
||||||
procs["pg1"]["status"] == "Running"
|
echo 'SELECT version();' | psql -h 127.0.0.1 ${dbName}
|
||||||
)
|
'';
|
||||||
machine.succeed("echo 'SELECT version();' | ${config.services.postgres.pg1.package}/bin/psql -h 127.0.0.1 -U tester ${dbName}")
|
};
|
||||||
'';
|
depends_on."pg1".condition = "process_healthy";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
|
4
justfile
4
justfile
@ -8,3 +8,7 @@ ex:
|
|||||||
# Auto-format the project tree
|
# Auto-format the project tree
|
||||||
fmt:
|
fmt:
|
||||||
treefmt
|
treefmt
|
||||||
|
|
||||||
|
# Run native tests
|
||||||
|
test:
|
||||||
|
nix flake check test/ --override-input services-flake . -L
|
||||||
|
@ -5,32 +5,25 @@
|
|||||||
initialScript.before = "CREATE USER bar;";
|
initialScript.before = "CREATE USER bar;";
|
||||||
initialScript.after = "CREATE DATABASE foo OWNER bar;";
|
initialScript.after = "CREATE DATABASE foo OWNER bar;";
|
||||||
};
|
};
|
||||||
services.postgres."pg2" = {
|
settings.processes.test =
|
||||||
enable = true;
|
|
||||||
listen_addresses = "127.0.0.1";
|
|
||||||
port = 5433;
|
|
||||||
};
|
|
||||||
testScript =
|
|
||||||
let
|
let
|
||||||
cfg = config.services.postgres."pg1";
|
cfg = config.services.postgres."pg1";
|
||||||
psql =
|
|
||||||
"${cfg.package}/bin/psql";
|
|
||||||
in
|
in
|
||||||
''
|
{
|
||||||
process_compose.wait_until(lambda procs:
|
command = pkgs.writeShellApplication {
|
||||||
# TODO: Check for 'ready'
|
runtimeInputs = [ cfg.package pkgs.gnugrep ];
|
||||||
procs["pg1"]["status"] == "Running"
|
text = ''
|
||||||
)
|
echo 'SELECT version();' | psql -h 127.0.0.1
|
||||||
process_compose.wait_until(lambda procs:
|
echo 'SHOW hba_file;' | psql -h 127.0.0.1 | ${pkgs.gawk}/bin/awk 'NR==3' | grep '^ /nix/store'
|
||||||
procs["pg2"]["status"] == "Running"
|
|
||||||
)
|
# initialScript.before test
|
||||||
machine.succeed("echo 'SELECT version();' | ${psql} -h 127.0.0.1 -U tester")
|
echo "SELECT 1 FROM pg_roles WHERE rolname = 'bar';" | psql -h 127.0.0.1 | grep -q 1
|
||||||
# Test if `pg2` is listening on the correct port
|
|
||||||
machine.succeed("echo 'SELECT version();' | ${psql} -h 127.0.0.1 -p 5433 -U tester")
|
# initialScript.after test
|
||||||
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'")
|
echo "SELECT 1 FROM pg_database WHERE datname = 'foo';" | psql -h 127.0.0.1 | grep -q 1
|
||||||
# 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")
|
name = "postgres-test";
|
||||||
# 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")
|
depends_on."pg1".condition = "process_healthy";
|
||||||
'';
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
{ config, ... }: {
|
{ pkgs, config, ... }: {
|
||||||
services.redis-cluster."c1".enable = true;
|
services.redis-cluster."c1".enable = true;
|
||||||
testScript = ''
|
|
||||||
process_compose.wait_until(lambda procs:
|
settings.processes.test =
|
||||||
# TODO: Check for 'is_ready' of `c1-cluster-create` instead of `c1-n1` (status of `c1-cluster-create` determines whether the hashslots are assigned).
|
let
|
||||||
# This should be easy after https://github.com/juspay/services-flake/issues/32
|
cfg = config.services.redis-cluster."c1";
|
||||||
procs["c1-n1"]["status"] == "Running"
|
in
|
||||||
)
|
{
|
||||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30001 ping | grep -q 'PONG'")
|
command = pkgs.writeShellApplication {
|
||||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30002 ping | grep -q 'PONG'")
|
runtimeInputs = [ cfg.package pkgs.gnugrep ];
|
||||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30003 ping | grep -q 'PONG'")
|
text = ''
|
||||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30004 ping | grep -q 'PONG'")
|
redis-cli -p 30001 ping | grep -q "PONG"
|
||||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30005 ping | grep -q 'PONG'")
|
redis-cli -p 30002 ping | grep -q "PONG"
|
||||||
machine.succeed("${config.services.redis-cluster.c1.package}/bin/redis-cli -p 30006 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."redis1".enable = true;
|
||||||
services.redis."redis2" = {
|
|
||||||
enable = true;
|
settings.processes.test =
|
||||||
port = 6380;
|
let
|
||||||
};
|
cfg = config.services.redis."redis1";
|
||||||
testScript = ''
|
in
|
||||||
process_compose.wait_until(lambda procs:
|
{
|
||||||
# TODO: Check for 'is_ready' instead of 'status'
|
command = pkgs.writeShellApplication {
|
||||||
procs["redis1"]["status"] == "Running"
|
runtimeInputs = [ cfg.package pkgs.gnugrep ];
|
||||||
)
|
text = ''
|
||||||
process_compose.wait_until(lambda procs:
|
redis-cli ping | grep -q "PONG"
|
||||||
procs["redis2"]["status"] == "Running"
|
'';
|
||||||
)
|
name = "redis-test";
|
||||||
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'")
|
depends_on."redis1".condition = "process_healthy";
|
||||||
'';
|
};
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1686089707,
|
"lastModified": 1691464053,
|
||||||
"narHash": "sha256-LTNlJcru2qJ0XhlhG9Acp5KyjB774Pza3tRH0pKIb3o=",
|
"narHash": "sha256-D21ctOBjr2Y3vOFRXKRoFr6uNBvE8q5jC4RrMxRZXTM=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "af21c31b2a1ec5d361ed8050edd0303c31306397",
|
"rev": "844ffa82bbe2a2779c86ab3a72ff1b4176cec467",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -54,11 +54,11 @@
|
|||||||
},
|
},
|
||||||
"process-compose-flake": {
|
"process-compose-flake": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689622628,
|
"lastModified": 1692810585,
|
||||||
"narHash": "sha256-V2FEzYpjBYed5Sf6zngbyk7Z0mClxvSu8jawRs0fvRE=",
|
"narHash": "sha256-Zc8nDSVkTUskB5mp9fh1mmOIUvx2pJ5V/Uq/0kxQ6B0=",
|
||||||
"owner": "Platonic-Systems",
|
"owner": "Platonic-Systems",
|
||||||
"repo": "process-compose-flake",
|
"repo": "process-compose-flake",
|
||||||
"rev": "67949a2e1c720838e233d3e7397ccddd7c9d4188",
|
"rev": "2a84a6c2c91c6244e5db8fd46551d5e7f31a85d3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -15,18 +15,22 @@
|
|||||||
perSystem = { self', pkgs, lib, ... }: {
|
perSystem = { self', pkgs, lib, ... }: {
|
||||||
process-compose = {
|
process-compose = {
|
||||||
postgres = {
|
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 = [
|
imports = [
|
||||||
inputs.services-flake.processComposeModules.default
|
inputs.services-flake.processComposeModules.default
|
||||||
../nix/postgres_test.nix
|
../nix/postgres_test.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
redis = {
|
redis = {
|
||||||
|
port = 0;
|
||||||
imports = [
|
imports = [
|
||||||
inputs.services-flake.processComposeModules.default
|
inputs.services-flake.processComposeModules.default
|
||||||
../nix/redis_test.nix
|
../nix/redis_test.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
redis-cluster = {
|
redis-cluster = {
|
||||||
|
port = 0;
|
||||||
imports = [
|
imports = [
|
||||||
inputs.services-flake.processComposeModules.default
|
inputs.services-flake.processComposeModules.default
|
||||||
../nix/redis-cluster_test.nix
|
../nix/redis-cluster_test.nix
|
||||||
|
Loading…
Reference in New Issue
Block a user