From 2b6fe3361fc28a2f362e54381be932d898025d69 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:39:11 -0400 Subject: [PATCH] Add test (#13) --- .github/workflows/ci.yaml | 10 +++- .gitignore | 5 +- test/flake.lock | 113 ++++++++++++++++++++++++++++++++++++++ test/flake.nix | 52 ++++++++++++++++++ test/test.sh | 3 + 5 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 test/flake.lock create mode 100644 test/flake.nix create mode 100755 test/test.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f2bc2bf..de7735a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,8 +11,14 @@ jobs: - uses: actions/checkout@v3 - name: Install Nix uses: DeterminateSystems/nix-installer-action@main - - name: Run test - id: test + - name: Build example flake + id: example run: | cd ./example nix build -L --override-input process-compose-flake .. + - name: Run test + id: test + run: | + cd ./test + ./test.sh + diff --git a/.gitignore b/.gitignore index 474f647..09d417b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /example/data.sqlite -/example/result \ No newline at end of file +/example/result + +/test/data.sqlite +/test/result.txt \ No newline at end of file diff --git a/test/flake.lock b/test/flake.lock new file mode 100644 index 0000000..cad1de9 --- /dev/null +++ b/test/flake.lock @@ -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 +} diff --git a/test/flake.nix b/test/flake.nix new file mode 100644 index 0000000..41b78a2 --- /dev/null +++ b/test/flake.nix @@ -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"; + }; + }; + }; + }; + }; + }; +} diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..41815ac --- /dev/null +++ b/test/test.sh @@ -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)