about summary refs log tree commit diff
path: root/nixos/tests/varnish.nix
diff options
context:
space:
mode:
authorajs124 <git@ajs124.de>2022-09-27 21:22:21 +0200
committerajs124 <git@ajs124.de>2022-09-27 21:45:27 +0200
commit85e999f9023e76255cde8e4bde2ec8e45266d93d (patch)
tree5fcae44c62baafdcc753480a46dab2b1e673b9a3 /nixos/tests/varnish.nix
parent04d71bccc1e9c98abde3b9496f7c6ac8edff856a (diff)
nixos/tests/varnish: init
Diffstat (limited to 'nixos/tests/varnish.nix')
-rw-r--r--nixos/tests/varnish.nix55
1 files changed, 55 insertions, 0 deletions
diff --git a/nixos/tests/varnish.nix b/nixos/tests/varnish.nix
new file mode 100644
index 0000000000000..9dcdeec9d8c8f
--- /dev/null
+++ b/nixos/tests/varnish.nix
@@ -0,0 +1,55 @@
+{
+  system ? builtins.currentSystem
+, pkgs ? import ../.. { inherit system; }
+, package
+}:
+import ./make-test-python.nix ({ pkgs, ... }: let
+  testPath = pkgs.hello;
+in {
+  name = "varnish";
+  meta = with pkgs.lib.maintainers; {
+    maintainers = [ ajs124 ];
+  };
+
+  nodes = {
+    varnish = { config, pkgs, ... }: {
+        services.nix-serve = {
+          enable = true;
+        };
+
+        services.varnish = {
+          inherit package;
+          enable = true;
+          http_address = "0.0.0.0:80";
+          config = ''
+            vcl 4.0;
+
+            backend nix-serve {
+              .host = "127.0.0.1";
+              .port = "${toString config.services.nix-serve.port}";
+            }
+          '';
+        };
+
+        networking.firewall.allowedTCPPorts = [ 80 ];
+        system.extraDependencies = [ testPath ];
+      };
+
+    client = { lib, ... }: {
+      nix.settings = {
+        require-sigs = false;
+        substituters = lib.mkForce [ "http://varnish" ];
+      };
+    };
+  };
+
+  testScript = ''
+    start_all()
+    varnish.wait_for_open_port(80)
+
+    client.wait_until_succeeds("curl -f http://varnish/nix-cache-info");
+
+    client.wait_until_succeeds("nix-store -r ${testPath}");
+    client.succeed("${testPath}/bin/hello");
+  '';
+})