nixos/tests/openresty-lua: test openresty with lua

related to #140655
This commit is contained in:
Bruno Bigras 2021-10-06 23:36:02 -04:00
parent 2ceae2db61
commit feb47656e4
4 changed files with 63 additions and 1 deletions

View File

@ -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 {};

View File

@ -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"
'';
})

View File

@ -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 {

View File

@ -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";