summaryrefslogtreecommitdiffstats
path: root/nixos/tests/nginx.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/tests/nginx.nix')
-rw-r--r--nixos/tests/nginx.nix60
1 files changed, 43 insertions, 17 deletions
diff --git a/nixos/tests/nginx.nix b/nixos/tests/nginx.nix
index d66d99821c11..d0b7306ae83b 100644
--- a/nixos/tests/nginx.nix
+++ b/nixos/tests/nginx.nix
@@ -3,15 +3,15 @@
# generated virtual hosts config.
# 2. whether the ETag header is properly generated whenever we're serving
# files in Nix store paths
-
+# 3. nginx doesn't restart on configuration changes (only reloads)
import ./make-test.nix ({ pkgs, ... }: {
name = "nginx";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ mbbx6spp ];
};
- nodes = let
- commonConfig = { pkgs, ... }: {
+ nodes = {
+ webserver = { pkgs, lib, ... }: {
services.nginx.enable = true;
services.nginx.commonHttpConfig = ''
log_format ceeformat '@cee: {"status":"$status",'
@@ -32,30 +32,42 @@ import ./make-test.nix ({ pkgs, ... }: {
location /favicon.ico { allow all; access_log off; log_not_found off; }
'';
};
+
services.nginx.virtualHosts.localhost = {
root = pkgs.runCommand "testdir" {} ''
mkdir "$out"
echo hello world > "$out/index.html"
'';
};
- };
- in {
- webserver = commonConfig;
- newwebserver = { pkgs, lib, ... }: {
- imports = [ commonConfig ];
- services.nginx.virtualHosts.localhost = {
- root = lib.mkForce (pkgs.runCommand "testdir2" {} ''
- mkdir "$out"
- echo hello world > "$out/index.html"
- '');
- };
+ services.nginx.enableReload = true;
+
+ nesting.clone = [
+ {
+ services.nginx.virtualHosts.localhost = {
+ root = lib.mkForce (pkgs.runCommand "testdir2" {} ''
+ mkdir "$out"
+ echo content changed > "$out/index.html"
+ '');
+ };
+ }
+
+ {
+ services.nginx.virtualHosts."1.my.test".listen = [ { addr = "127.0.0.1"; port = 8080; }];
+ }
+
+ {
+ services.nginx.package = pkgs.nginxUnstable;
+ }
+ ];
};
+
};
testScript = { nodes, ... }: let
- newServerSystem = nodes.newwebserver.config.system.build.toplevel;
- switch = "${newServerSystem}/bin/switch-to-configuration test";
+ etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
+ justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
+ reloadRestartSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-3";
in ''
my $url = 'http://localhost/index.html';
@@ -77,9 +89,23 @@ import ./make-test.nix ({ pkgs, ... }: {
subtest "check ETag if serving Nix store paths", sub {
my $oldEtag = checkEtag;
- $webserver->succeed('${switch}');
+ $webserver->succeed("${etagSystem}/bin/switch-to-configuration test >&2");
+ $webserver->sleep(1); # race condition
my $newEtag = checkEtag;
die "Old ETag $oldEtag is the same as $newEtag" if $oldEtag eq $newEtag;
};
+
+ subtest "config is reloaded on nixos-rebuild switch", sub {
+ $webserver->succeed("${justReloadSystem}/bin/switch-to-configuration test >&2");
+ $webserver->waitForOpenPort("8080");
+ $webserver->fail("journalctl -u nginx | grep -q -i stopped");
+ $webserver->succeed("journalctl -u nginx | grep -q -i reloaded");
+ };
+
+ subtest "restart when nginx package changes", sub {
+ $webserver->succeed("${reloadRestartSystem}/bin/switch-to-configuration test >&2");
+ $webserver->waitForUnit("nginx");
+ $webserver->succeed("journalctl -u nginx | grep -q -i stopped");
+ };
'';
})