From c39d7db5cd55d5e9ca3c246a36e744b85ae7063c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 2 Jan 2019 09:54:46 +0100 Subject: [PATCH] Add integration test Tests the minimal example, up command, network connectivity. Introduces overlay. --- arion.nix | 18 ++++++++++++++++++ default.nix | 26 +++----------------------- pkgs.nix | 3 +++ tests/arion-test/default.nix | 34 ++++++++++++++++++++++++++++++++++ tests/default.nix | 8 ++++++++ 5 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 arion.nix create mode 100644 pkgs.nix create mode 100644 tests/arion-test/default.nix create mode 100644 tests/default.nix diff --git a/arion.nix b/arion.nix new file mode 100644 index 0000000..9ca4c24 --- /dev/null +++ b/arion.nix @@ -0,0 +1,18 @@ +{ stdenv, lib, jq, coreutils }: + +stdenv.mkDerivation { + name = "arion"; + src = ./src; + unpackPhase = ""; + buildPhase = ""; + installPhase = '' + mkdir -p $out/bin $out/share/arion + cp -a nix $out/share/arion/ + cp -a arion-image $out/share/arion/ + substitute arion $out/bin/arion \ + --subst-var-by path ${lib.makeBinPath [jq coreutils]} \ + --subst-var-by nix_dir $out/share/arion/nix \ + ; + chmod a+x $out/bin/arion + ''; +} diff --git a/default.nix b/default.nix index 440e4b5..226f2a6 100644 --- a/default.nix +++ b/default.nix @@ -1,26 +1,6 @@ -{ pkgs ? import {} }: +{ pkgs ? import ./pkgs.nix }: -let - inherit (pkgs) lib stdenv; - - arion = stdenv.mkDerivation { - name = "arion"; - src = ./src; - unpackPhase = ""; - buildPhase = ""; - installPhase = '' - mkdir -p $out/bin $out/share/arion - cp -a nix $out/share/arion/ - cp -a arion-image $out/share/arion/ - substitute arion $out/bin/arion \ - --subst-var-by path ${lib.makeBinPath [pkgs.jq pkgs.coreutils]} \ - --subst-var-by nix_dir $out/share/arion/nix \ - ; - chmod a+x $out/bin/arion - ''; - }; - -in { - inherit arion; + inherit (pkgs) arion; + tests = pkgs.callPackage ./tests {}; } diff --git a/pkgs.nix b/pkgs.nix new file mode 100644 index 0000000..f608d1a --- /dev/null +++ b/pkgs.nix @@ -0,0 +1,3 @@ +import { + overlays = [ (self: super: { arion = super.callPackage ./arion.nix {}; }) ]; +} diff --git a/tests/arion-test/default.nix b/tests/arion-test/default.nix new file mode 100644 index 0000000..932a221 --- /dev/null +++ b/tests/arion-test/default.nix @@ -0,0 +1,34 @@ +{ pkgs, ... }: + +let + # To make some prebuilt derivations available in the vm + preEval = import ../../src/nix/eval-docker-compose.nix { + modules = [ ../../examples/minimal/arion-compose.nix ]; + inherit pkgs; + }; +in +{ + name = "arion-test"; + machine = { pkgs, lib, ... }: { + environment.systemPackages = [ + pkgs.arion + pkgs.docker-compose + ]; + virtualisation.docker.enable = true; + + # no caches, because no internet + nix.binaryCaches = lib.mkForce []; + virtualisation.writableStore = true; + virtualisation.pathsInNixDB = [ + # Pre-build the image because we don't want to build the world + # in the vm. + preEval.config.build.dockerComposeYaml + ]; + }; + testScript = '' + $machine->fail("curl localhost:8000"); + $machine->succeed("docker --version"); + $machine->succeed("cp -r ${../../examples/minimal} work && cd work && NIX_PATH=nixpkgs='${pkgs.path}' arion up -d"); + $machine->waitUntilSucceeds("curl localhost:8000"); + ''; +} diff --git a/tests/default.nix b/tests/default.nix new file mode 100644 index 0000000..27bbac2 --- /dev/null +++ b/tests/default.nix @@ -0,0 +1,8 @@ +{ pkgs ? import ../pkgs.nix }: +let + inherit (pkgs) nixosTest recurseIntoAttrs; +in + +recurseIntoAttrs { + test = nixosTest ./arion-test; +}