1 import ./make-test-python.nix ({lib, pkgs, ...}:
4 192.168.2.101 example.com
5 192.168.2.101 api.example.com
6 192.168.2.101 backend.example.com
12 meta.maintainers = with pkgs.lib.maintainers; [ izorkin ];
15 server = { pkgs, ... }: {
19 { address = "192.168.2.101"; prefixLength = 24; }
23 firewall.allowedTCPPorts = [ 80 ];
32 servers = { "backend.example.com:8080" = { fail_timeout = "0"; }; };
38 servers = { "unix:/run/example.sock" = { fail_timeout = "0"; }; };
45 virtualHosts."api.example.com" = {
46 locations."/console/" = {
56 virtualHosts."example.com" = {
57 locations."/test/" = {
58 root = lib.mkForce (pkgs.runCommandLocal "testdir" {} ''
60 cat > "$out/test/index.html" <<EOF
61 <html><body>Hello World!</body></html>
65 status_zone test_zone;
71 locations."/test/locked/" = {
73 status_zone test_zone;
78 locations."/test/error/" = {
80 status_zone test_zone;
85 locations."/upstream-http/" = {
86 proxyPass = "http://backend-http";
88 locations."/upstream-socket/" = {
89 proxyPass = "http://backend-socket";
95 client = { pkgs, ... }: {
96 environment.systemPackages = [ pkgs.jq ];
100 { address = "192.168.2.201"; prefixLength = 24; }
111 server.wait_for_unit("nginx")
112 server.wait_for_open_port(80)
114 # Check Angie version
115 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.angie.version' | grep '${pkgs.angie.version}'")
118 client.succeed("curl --verbose --head http://api.example.com/console/ | grep 'HTTP/1.1 200'")
119 server.succeed("curl --verbose --head http://api.example.com/console/ | grep 'HTTP/1.1 403 Forbidden'")
121 # Check responses and requests
122 client.succeed("curl --verbose http://example.com/test/")
123 client.succeed("curl --verbose http://example.com/test/locked/")
124 client.succeed("curl --verbose http://example.com/test/locked/")
125 client.succeed("curl --verbose http://example.com/test/error/")
126 client.succeed("curl --verbose http://example.com/test/error/")
127 client.succeed("curl --verbose http://example.com/test/error/")
128 server.succeed("curl --verbose http://example.com/test/")
129 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.location_zones.test_zone.responses.\"200\"' | grep '1'")
130 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.location_zones.test_zone.responses.\"403\"' | grep '3'")
131 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.location_zones.test_zone.responses.\"404\"' | grep '3'")
132 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.location_zones.test_zone.requests.total' | grep '7'")
135 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.upstreams.\"backend-http\".peers.\"192.168.2.101:8080\".state' | grep 'up'")
136 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.upstreams.\"backend-http\".peers.\"192.168.2.101:8080\".health.fails' | grep '0'")
137 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.upstreams.\"backend-socket\".peers.\"unix:/run/example.sock\".state' | grep 'up'")
138 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.upstreams.\"backend-socket\".peers.\"unix:/run/example.sock\".health.fails' | grep '0'")
139 client.succeed("curl --verbose http://example.com/upstream-http/")
140 client.succeed("curl --verbose http://example.com/upstream-socket/")
141 client.succeed("curl --verbose http://example.com/upstream-socket/")
142 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.upstreams.\"backend-http\".peers.\"192.168.2.101:8080\".health.fails' | grep '1'")
143 client.succeed("curl --verbose http://api.example.com/console/ | jq -e '.http.upstreams.\"backend-socket\".peers.\"unix:/run/example.sock\".health.fails' | grep '2'")