vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / geoserver.nix
blob4f6f2b209d07f6e3cd283025b60a5763ae381e2c
1 { pkgs, lib, ... }:
3 let
4   geoserver = pkgs.geoserver;
5   geoserverWithImporterExtension = pkgs.geoserver.withExtensions (ps: with ps; [ importer ]);
7   # Blacklisted extensions:
8   # - wps-jdbc needs a running (Postrgres) db server.
9   blacklist = [ "wps-jdbc" ];
11   blacklistedToNull = n: v: if ! builtins.elem n blacklist then v else null;
12   getNonBlackistedExtensionsAsList = ps: builtins.filter (x: x != null) (lib.attrsets.mapAttrsToList blacklistedToNull ps);
13   geoserverWithAllExtensions = pkgs.geoserver.withExtensions (ps: getNonBlackistedExtensionsAsList ps);
17   name = "geoserver";
18   meta = {
19     maintainers = with lib; [ teams.geospatial.members ];
20   };
22   nodes = {
23     machine = { pkgs, ... }: {
24       virtualisation.diskSize = 2 * 1024;
26       environment.systemPackages = [
27         geoserver
28         geoserverWithImporterExtension
29         geoserverWithAllExtensions
30       ];
31     };
32   };
34   testScript = ''
35     from contextlib import contextmanager
37     curl_cmd = "curl --fail --connect-timeout 2"
38     curl_cmd_rest = f"{curl_cmd} -u admin:geoserver -X GET"
39     base_url = "http://localhost:8080/geoserver"
40     log_file = "./log.txt"
42     @contextmanager
43     def running_geoserver(pkg):
44       try:
45         print(f"Launching geoserver from {pkg}...")
46         machine.execute(f"{pkg}/bin/geoserver-startup > {log_file} 2>&1 &")
47         machine.wait_until_succeeds(f"{curl_cmd} {base_url} 2>&1", timeout=60)
48         yield
49       finally:
50         # We need to wait a little bit to make sure the server is properly
51         # shutdown before launching a new instance.
52         machine.execute(f"{pkg}/bin/geoserver-shutdown; sleep 1")
54     start_all()
56     with running_geoserver("${geoserver}"):
57       machine.succeed(f"{curl_cmd} {base_url}/ows?service=WMS&version=1.3.0&request=GetCapabilities")
59       # No extensions yet.
60       machine.fail(f"{curl_cmd_rest} {base_url}/rest/imports")
61       machine.fail(f"{curl_cmd_rest} {base_url}/rest/monitor/requests.csv")
64     with running_geoserver("${geoserverWithImporterExtension}"):
65       machine.succeed(f"{curl_cmd_rest} {base_url}/rest/imports")
66       machine.fail(f"{curl_cmd_rest} {base_url}/rest/monitor/requests.csv")
68     with running_geoserver("${geoserverWithAllExtensions}"):
69       machine.succeed(f"{curl_cmd_rest} {base_url}/rest/imports")
70       machine.succeed(f"{curl_cmd_rest} {base_url}/rest/monitor/requests.csv")
71       _, stdout = machine.execute(f"cat {log_file}")
72       print(stdout.replace("\\n", "\n"))
73       assert "GDAL Native Library loaded" in stdout, "gdal"
74       assert "The turbo jpeg encoder is available for usage" in stdout, "libjpeg-turbo"
75       assert "org.geotools.imageio.netcdf.utilities.NetCDFUtilities" in stdout, "netcdf"
76       assert "Unable to load library 'netcdf'" not in stdout, "netcdf"
78   '';