diff --git a/docs/tutorials/integrationtests.md b/docs/tutorials/integrationtests.md new file mode 100644 index 0000000..b4bef9d --- /dev/null +++ b/docs/tutorials/integrationtests.md @@ -0,0 +1,6 @@ +# Integration Tests + +Integration tests configure real virtual machines and run tests on +those to assert some properties. + +You can find all integration tests under the [tests/integration](/tests/integration) directory. diff --git a/tests/integration/common.nix b/tests/integration/common.nix new file mode 100644 index 0000000..f2d519f --- /dev/null +++ b/tests/integration/common.nix @@ -0,0 +1,40 @@ +{ nixpkgs, pkgs }: +let + generateManifestSrc = + {name, tarball}: + + pkgs.stdenv.mkDerivation { + name = "${name}-manifest-src"; + buildCommand = + '' + mkdir -p $out + cd $out + tar xfvj ${tarball}/tarballs/*.tar.bz2 --strip-components=1 + ''; + }; +in +{ + disnixTest = system: + {name, manifest, tarball, networkFile, externalNetworkFile ? false, testScript, dysnomiaStateDir ? "", postActivateTimeout ? 1}: + + let + manifestSrc = generateManifestSrc { + inherit name tarball; + }; + + network = if externalNetworkFile then import networkFile else import "${manifestSrc}/${networkFile}"; + in + with import "${nixpkgs}/nixos/lib/testing-python.nix" { inherit system; }; + + simpleTest { + nodes = network; + inherit name; + + testScript = import "${pkgs.disnixos}/share/disnixos/generate-testscript.nix" { + inherit network testScript dysnomiaStateDir postActivateTimeout; + inherit (pkgs) disnix daemon socat libxml2; + inherit (pkgs.lib) concatMapStrings; + manifestFile = "${manifest}/manifest.xml"; + }; + }; +} diff --git a/tests/integration/default.nix b/tests/integration/default.nix new file mode 100644 index 0000000..76b0ab0 --- /dev/null +++ b/tests/integration/default.nix @@ -0,0 +1,6 @@ +{ pkgs +, utils +}: +{ + keycloak = pkgs.callPackage ./keycloak.nix {}; +} diff --git a/tests/disnix/keycloak.nix b/tests/integration/keycloak.nix similarity index 51% rename from tests/disnix/keycloak.nix rename to tests/integration/keycloak.nix index 35845a9..334c3fd 100644 --- a/tests/disnix/keycloak.nix +++ b/tests/integration/keycloak.nix @@ -1,58 +1,75 @@ { nixpkgs ? -, system ? builtins.currentSystem +, systems ? [ "i686-linux" "x86_64-linux" ] }: let - pkgs = import nixpkgs {inherit system;}; + pkgs = import nixpkgs {}; disnixos = import "${pkgs.disnixos}/share/disnixos/testing.nix" { - inherit nixpkgs system; + inherit nixpkgs; }; version = "1.0"; + + disnixos2 = pkgs.callPackage ./common.nix { inherit nixpkgs; }; in rec { tarball = disnixos.sourceTarball { name = "testproject-zip"; inherit version; - src = ./.; + src = ../../.; officialRelease = false; }; - manifest = - disnixos.buildManifest { - name = "test-project-manifest"; - version = builtins.readFile ./version; - inherit tarball; - servicesFile = "keycloak/services.nix"; - networkFile = "keycloak/network.nix"; - distributionFile = "keycloak/distribution.nix"; - }; + builds = { + simple = pkgs.lib.genAttrs systems (system: + let + pkgs = import nixpkgs { inherit system; }; - tests = - disnixos.disnixTest { - name = "test-project-tests"; - inherit tarball manifest; - networkFile = "keycloak/network.nix"; - dysnomiaStateDir = /var/state/dysnomia; + disnixos = import "${pkgs.disnixos}/share/disnixos/testing.nix" { + inherit nixpkgs system; + }; + in + disnixos.buildManifest { + name = "test-project-manifest"; + inherit version; + inherit tarball; + servicesFile = "tests/integration/keycloak/services.nix"; + networkFile = "tests/integration/keycloak/network.nix"; + distributionFile = "tests/integration/keycloak/distribution.nix"; + # extraParams = { + # "extra-builtins-file" = ../../extra-builtins.nix; + # }; + } + ); + }; + + tests = { + simple = disnixos2.disnixTest builtins.currentSystem { + name = "test-project-test"; + inherit tarball; + manifest = builtins.getAttr (builtins.currentSystem) builds.simple; + networkFile = "tests/integration/keycloak/network.nix"; + # dysnomiaStateDir = /var/state/dysnomia; testScript = '' - # Wait until the front-end application is deployed - $test1->waitForFile("/var/tomcat/webapps/testapp"); - - # Wait a little longer and capture the output of the entry page - my $result = $test1->mustSucceed("sleep 10; curl --fail http://test2:8080/testapp"); + # Wait until the front-end application is deployed + # $test1->waitForFile("/var/tomcat/webapps/testapp"); + + # Wait a little longer and capture the output of the entry page + # my $result = $test1->mustSucceed("sleep 10; curl --fail http://test2:8080/testapp"); ''; }; -} + }; +}.tests # let # utils = import ../../utils.nix { # inherit pkgs; # inherit (pkgs) stdenv lib; # }; -# keycloak = import ../../pkgs/keycloak/unit.nix { +# keycloak = import ../../keycloak/unit.nix { # inherit pkgs utils; # inherit (pkgs) stdenv lib; # }; diff --git a/tests/disnix/keycloak/distribution.nix b/tests/integration/keycloak/distribution.nix similarity index 100% rename from tests/disnix/keycloak/distribution.nix rename to tests/integration/keycloak/distribution.nix diff --git a/tests/disnix/keycloak/network.nix b/tests/integration/keycloak/network.nix similarity index 85% rename from tests/disnix/keycloak/network.nix rename to tests/integration/keycloak/network.nix index 92ba912..bfba6b5 100644 --- a/tests/disnix/keycloak/network.nix +++ b/tests/integration/keycloak/network.nix @@ -8,7 +8,7 @@ rec { utils = pkgs.lib.callPackageWith pkgs ../../../utils.nix { }; - customPkgs = import ../../../pkgs/all-packages.nix { + customPkgs = import ../../../all-packages.nix { inherit system pkgs utils; }; in @@ -26,11 +26,11 @@ rec { }; }; - deployment.keys = { - keycloakinitialadmin.text = '' - KEYCLOAK_ADMIN_PASSWORD="${builtins.extraBuiltins.pass "keycloak.${domain}/admin"}" - ''; - }; + # deployment.keys = { + # keycloakinitialadmin.text = '' + # KEYCLOAK_ADMIN_PASSWORD="${builtins.extraBuiltins.pass "keycloak.${domain}/admin"}" + # ''; + # }; services = { openssh = { diff --git a/tests/disnix/keycloak/services.nix b/tests/integration/keycloak/services.nix similarity index 71% rename from tests/disnix/keycloak/services.nix rename to tests/integration/keycloak/services.nix index 33de6ca..44a7caa 100644 --- a/tests/disnix/keycloak/services.nix +++ b/tests/integration/keycloak/services.nix @@ -3,11 +3,12 @@ let utils = pkgs.lib.callPackageWith pkgs ../../../utils.nix { }; - customPkgs = import ../../../pkgs/all-packages.nix { + customPkgs = import ../../../all-packages.nix { inherit system pkgs utils; }; in -{ +with utils; +rec { KeycloakPostgresDB = customPkgs.mkPostgresDB { name = "KeycloakPostgresDB"; database = "keycloak"; @@ -18,12 +19,13 @@ in KeycloakService = customPkgs.mkKeycloakService { name = "KeycloakService"; + subdomain = "keycloak"; # Get these from infrastructure.nix user = "keycloak"; group = "keycloak"; - postgresServiceName = (utils.getTarget "KeycloakPostgresDB").containers.postgresql-database.service_name; + postgresServiceName = (getTarget distribution "KeycloakPostgresDB").containers.postgresql-database.service_name; initialAdminUsername = "admin"; keys = { @@ -32,13 +34,13 @@ in }; logLevel = "INFO"; - hostname = "keycloak.${getDomain "KeycloakService"}"; + hostname = "keycloak.${getDomain distribution "KeycloakService"}"; dbType = "postgres"; dbDatabase = KeycloakPostgresDB.database; dbUsername = KeycloakPostgresDB.username; dbHost = {KeycloakPostgresDB}: KeycloakPostgresDB.target.properties.hostname; - dbPort = (getTarget "KeycloakPostgresDB").containers.postgresql-database.port; + dbPort = (getTarget distribution "KeycloakPostgresDB").containers.postgresql-database.port; inherit KeycloakPostgresDB; };