From feb47656e4d36a355b4f889e6f9c4c14a8f255c4 Mon Sep 17 00:00:00 2001 From: Bruno Bigras Date: Wed, 6 Oct 2021 23:36:02 -0400 Subject: [PATCH] nixos/tests/openresty-lua: test openresty with lua related to #140655 --- nixos/tests/all-tests.nix | 1 + nixos/tests/openresty-lua.nix | 55 +++++++++++++++++++++++++ pkgs/servers/http/nginx/generic.nix | 3 +- pkgs/servers/http/openresty/default.nix | 5 +++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/openresty-lua.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a6eb2c032588..0f0245484898 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -322,6 +322,7 @@ in ombi = handleTest ./ombi.nix {}; openarena = handleTest ./openarena.nix {}; openldap = handleTest ./openldap.nix {}; + openresty-lua = handleTest ./openresty-lua.nix {}; opensmtpd = handleTest ./opensmtpd.nix {}; opensmtpd-rspamd = handleTest ./opensmtpd-rspamd.nix {}; openssh = handleTest ./openssh.nix {}; diff --git a/nixos/tests/openresty-lua.nix b/nixos/tests/openresty-lua.nix new file mode 100644 index 000000000000..b177b3c194d7 --- /dev/null +++ b/nixos/tests/openresty-lua.nix @@ -0,0 +1,55 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: + let + lualibs = [ + pkgs.lua.pkgs.markdown + ]; + + getPath = lib: type: "${lib}/share/lua/${pkgs.lua.luaversion}/?.${type}"; + getLuaPath = lib: getPath lib "lua"; + luaPath = lib.concatStringsSep ";" (map getLuaPath lualibs); + in + { + name = "openresty-lua"; + meta = with pkgs.lib.maintainers; { + maintainers = [ bbigras ]; + }; + + nodes = { + webserver = { pkgs, lib, ... }: { + services.nginx = { + enable = true; + package = pkgs.openresty; + + commonHttpConfig = '' + lua_package_path '${luaPath};;'; + ''; + + virtualHosts."default" = { + default = true; + locations."/" = { + extraConfig = '' + default_type text/html; + access_by_lua ' + local markdown = require "markdown" + markdown("source") + '; + ''; + }; + }; + }; + }; + }; + + testScript = { nodes, ... }: + '' + url = "http://localhost" + + webserver.wait_for_unit("nginx") + webserver.wait_for_open_port(80) + + http_code = webserver.succeed( + f"curl -w '%{{http_code}}' --head --fail {url}" + ) + assert http_code.split("\n")[-1] == "200" + ''; + }) diff --git a/pkgs/servers/http/nginx/generic.nix b/pkgs/servers/http/nginx/generic.nix index ecbf8071d611..7465589d636e 100644 --- a/pkgs/servers/http/nginx/generic.nix +++ b/pkgs/servers/http/nginx/generic.nix @@ -21,6 +21,7 @@ , preConfigure ? "" , postInstall ? null , meta ? null +, passthru ? { tests = {}; } }: with lib; @@ -146,7 +147,7 @@ stdenv.mkDerivation { inherit (nixosTests) nginx nginx-auth nginx-etag nginx-pubhtml nginx-sandbox nginx-sso; variants = lib.recurseIntoAttrs nixosTests.nginx-variants; acme-integration = nixosTests.acme; - }; + } // passthru.tests; }; meta = if meta != null then meta else { diff --git a/pkgs/servers/http/openresty/default.nix b/pkgs/servers/http/openresty/default.nix index 3c30b2c3ed0a..5c852de5b64a 100644 --- a/pkgs/servers/http/openresty/default.nix +++ b/pkgs/servers/http/openresty/default.nix @@ -3,6 +3,7 @@ , lib , fetchurl , postgresql +, nixosTests , ... }@args: @@ -42,6 +43,10 @@ callPackage ../nginx/generic.nix args rec { ln -s $out/nginx/html $out/html ''; + passthru.tests = { + inherit (nixosTests) openresty-lua; + }; + meta = { description = "A fast web application server built on Nginx"; homepage = "https://openresty.org";