mirror of
https://github.com/Platonic-Systems/process-compose-flake.git
synced 2024-09-11 14:07:00 +03:00
Add test (#13)
This commit is contained in:
parent
32bd49bb44
commit
2b6fe3361f
10
.github/workflows/ci.yaml
vendored
10
.github/workflows/ci.yaml
vendored
@ -11,8 +11,14 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: DeterminateSystems/nix-installer-action@main
|
uses: DeterminateSystems/nix-installer-action@main
|
||||||
- name: Run test
|
- name: Build example flake
|
||||||
id: test
|
id: example
|
||||||
run: |
|
run: |
|
||||||
cd ./example
|
cd ./example
|
||||||
nix build -L --override-input process-compose-flake ..
|
nix build -L --override-input process-compose-flake ..
|
||||||
|
- name: Run test
|
||||||
|
id: test
|
||||||
|
run: |
|
||||||
|
cd ./test
|
||||||
|
./test.sh
|
||||||
|
|
||||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
/example/data.sqlite
|
/example/data.sqlite
|
||||||
/example/result
|
/example/result
|
||||||
|
|
||||||
|
/test/data.sqlite
|
||||||
|
/test/result.txt
|
113
test/flake.lock
Normal file
113
test/flake.lock
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1685662779,
|
||||||
|
"narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1686089707,
|
||||||
|
"narHash": "sha256-LTNlJcru2qJ0XhlhG9Acp5KyjB774Pza3tRH0pKIb3o=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "af21c31b2a1ec5d361ed8050edd0303c31306397",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"dir": "lib",
|
||||||
|
"lastModified": 1685564631,
|
||||||
|
"narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"dir": "lib",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"process-compose-flake": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1680797953,
|
||||||
|
"narHash": "sha256-lFYbfId1IX6jh/wUf+gt3LyvE9HblS4hcBQcougSzX0=",
|
||||||
|
"owner": "Platonic-Systems",
|
||||||
|
"repo": "process-compose-flake",
|
||||||
|
"rev": "aee1b8d126a5efe5945513eb2fb343f3d68dca4b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "Platonic-Systems",
|
||||||
|
"repo": "process-compose-flake",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"process-compose-flake": "process-compose-flake",
|
||||||
|
"chinookDb": "chinookDb",
|
||||||
|
"systems": "systems"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chinookDb": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1645319735,
|
||||||
|
"narHash": "sha256-mrRf6ih55mHpaxiw+owvxLPVzRIbxxaj2rWEmLI5pZQ=",
|
||||||
|
"owner": "lerocha",
|
||||||
|
"repo": "chinook-database",
|
||||||
|
"rev": "e7e6d5f008e35d3f89d8b8a4f8d38e3bfa7e34bd",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "lerocha",
|
||||||
|
"repo": "chinook-database",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
52
test/flake.nix
Normal file
52
test/flake.nix
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
description = "process-compose-flake test";
|
||||||
|
inputs = {
|
||||||
|
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";
|
||||||
|
};
|
||||||
|
outputs = inputs:
|
||||||
|
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
|
systems = import inputs.systems;
|
||||||
|
imports = [
|
||||||
|
inputs.process-compose-flake.flakeModule
|
||||||
|
];
|
||||||
|
perSystem = { pkgs, lib, ... }: {
|
||||||
|
process-compose = {
|
||||||
|
# This adds a `self.packages.default`
|
||||||
|
configs."default" = {
|
||||||
|
processes = {
|
||||||
|
|
||||||
|
# Create .sqlite database from chinook database.
|
||||||
|
sqlite-init.command =
|
||||||
|
let
|
||||||
|
sqlFile = pkgs.writeTextFile {
|
||||||
|
name = "data.sql";
|
||||||
|
text = ''
|
||||||
|
CREATE TABLE demo (val TEXT);
|
||||||
|
INSERT INTO demo VALUES ("Hello");
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in ''
|
||||||
|
echo "`date`: Creating database..."
|
||||||
|
${lib.getExe pkgs.sqlite} data.sqlite < ${sqlFile}
|
||||||
|
echo "`date`: Done."
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Query something, write to result.txt
|
||||||
|
sqlite-query = {
|
||||||
|
command = ''
|
||||||
|
${lib.getExe pkgs.sqlite} data.sqlite \
|
||||||
|
'select val from demo where val = "Hello"' \
|
||||||
|
> result.txt
|
||||||
|
'';
|
||||||
|
# The 'depends_on' will have this process wait until the above one is completed.
|
||||||
|
depends_on."sqlite-init".condition = "process_completed_successfully";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
3
test/test.sh
Executable file
3
test/test.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
rm -f ./data.sqlite
|
||||||
|
nix run -L --override-input process-compose-flake .. . -- -t=false
|
||||||
|
[[ $(cat result.txt) == "Hello" ]] && echo "Test passed" || (echo "Test failed" && exit 1)
|
Loading…
Reference in New Issue
Block a user