From 85e999f9023e76255cde8e4bde2ec8e45266d93d Mon Sep 17 00:00:00 2001 From: ajs124 Date: Tue, 27 Sep 2022 21:22:21 +0200 Subject: [PATCH] nixos/tests/varnish: init --- nixos/tests/all-tests.nix | 3 +++ nixos/tests/varnish.nix | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 nixos/tests/varnish.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 5ea2c94ccb1c..688ebb373b0d 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -610,6 +610,9 @@ in { user-home-mode = handleTest ./user-home-mode.nix {}; uwsgi = handleTest ./uwsgi.nix {}; v2ray = handleTest ./v2ray.nix {}; + varnish60 = handleTest ./varnish.nix { package = pkgs.varnish60; }; + varnish71 = handleTest ./varnish.nix { package = pkgs.varnish71; }; + varnish72 = handleTest ./varnish.nix { package = pkgs.varnish72; }; vault = handleTest ./vault.nix {}; vault-dev = handleTest ./vault-dev.nix {}; vault-postgresql = handleTest ./vault-postgresql.nix {}; diff --git a/nixos/tests/varnish.nix b/nixos/tests/varnish.nix new file mode 100644 index 000000000000..9dcdeec9d8c8 --- /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"); + ''; +})