electron_32: fix log spam when building on aarch64-linux (#378988)
[NixPkgs.git] / pkgs / by-name / hi / hiawatha / test.nix
blob3287a62661271502a95d148471baf7f6873eb7b9
2   lib,
3   stdenvNoCC,
4   hiawatha,
5   curl,
6   mbedtls,
7   enableTls,
8 }:
10 stdenvNoCC.mkDerivation {
11   name = "hiawatha-test";
13   nativeBuildInputs = [
14     hiawatha
15     curl
16   ] ++ lib.optional enableTls mbedtls;
18   env = {
19     inherit enableTls;
20   };
22   buildCommand = ''
23     cp -r --no-preserve=mode ${hiawatha}/etc/hiawatha config
24     sed "1i set TEST_DIR = $(pwd)" $serverConfigPath > config/hiawatha.conf
26     mkdir www
27     echo "it works" > www/index.html
29     if [ -n "$enableTls" ]; then
30       echo "Generating self-signed certificate"
31       gen_key type=ec filename=server.key
32       cert_write selfsign=1 issuer_key=server.key output_file=server.crt
33       cat server.crt server.key > config/server.crt
34     fi
36     echo "Checking server configuration"
37     hiawatha -c ./config -k
39     echo "Starting server"
40     hiawatha -c ./config
42     testUrl() {
43       echo "Testing $1"
44       curl --verbose --insecure --fail "$1" | tee response
45       grep -q "it works" response
46     }
48     testUrl http://127.0.0.1:8000
49     if [ -n "$enableTls" ]; then
50       testUrl https://127.0.0.1:8443
51     fi
53     touch $out
54   '';
56   serverConfig = ''
57     # By default the server uses read-only directories like /var/lib and /etc
58     WorkDirectory = TEST_DIR
59     PIDfile = TEST_DIR/hiawatha.pid
60     SystemLogfile = TEST_DIR/system.log
61     GarbageLogfile = TEST_DIR/garbage.log
62     ExploitLogfile = TEST_DIR/exploit.log
63     AccessLogfile = TEST_DIR/access.log
64     ErrorLogfile = TEST_DIR/error.log
66     Binding {
67       Interface = 127.0.0.1
68       Port = 8000
69     }
71     ${lib.optionalString enableTls ''
72       Binding {
73         Interface = 127.0.0.1
74         Port = 8443
75         TLScertFile = TEST_DIR/config/server.crt
76       }
77     ''}
79     Hostname = 127.0.0.1
80     WebsiteRoot = TEST_DIR/www
81     StartFile = index.html
82   '';
84   passAsFile = [ "serverConfig" ];