test(nginx): Add simple tests to assert nginx features work
This commit is contained in:
parent
4e59582de2
commit
12790d5444
6 changed files with 178 additions and 2 deletions
|
|
@ -1,4 +1,10 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
flake-inputs,
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
hostNames = lib.attrNames config.services.nginx.virtualHosts;
|
||||
logPath = name: "/var/log/nginx/${name}/access.log";
|
||||
|
|
@ -80,5 +86,55 @@ in
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
serviceTests =
|
||||
let
|
||||
testHostConfig =
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
./.
|
||||
../../modules/serviceTests/mocks.nix
|
||||
];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 80 ];
|
||||
|
||||
services.nginx = {
|
||||
domain = "testHost";
|
||||
virtualHosts."${config.services.nginx.domain}".locations."/".return = "200 ok";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
nginxMetricsWork = pkgs.testers.runNixOSTest {
|
||||
name = "nginx-metrics-work";
|
||||
node.specialArgs = { inherit flake-inputs; };
|
||||
|
||||
nodes = {
|
||||
testHost = testHostConfig;
|
||||
|
||||
client =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = [ pkgs.curl ];
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
import time
|
||||
|
||||
start_all()
|
||||
|
||||
testHost.wait_for_unit("nginx.service")
|
||||
client.succeed("curl --max-time 10 http://testHost")
|
||||
|
||||
# Wait a bit for the prometheus exporter to scrape our logs
|
||||
time.sleep(5)
|
||||
|
||||
res = testHost.succeed("curl localhost:${builtins.toString config.services.prometheus.exporters.nginxlog.port}/metrics")
|
||||
assert 'nginxlog_http_response_count_total{method="GET",status="200",vhost="testHost"} 1' in res, res
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue