# Listens on HTTPS when enabled

cert $WORK karma
exec bash -x ./test.sh &
exec karma --pid-file=karma.pid --config.file=karma.yaml --listen.address=127.0.0.1 --listen.port=8087
! stdout .
exec sleep 5
cmp http1.txt pong.txt
cmp http2.txt pong.txt
wait

-- pong.txt --
Pong
-- stderr.txt --
level=info msg="Reading configuration file" path=karma.yaml
level=info msg="Version: dev"
level=info msg="Configured Alertmanager source" name=local proxy=false readonly=false uri=https://127.0.0.1:9093
level=info msg="Writing PID file" path=karma.pid
level=info msg="Initial Alertmanager collection"
level=info msg="Pulling latest alerts and silences from Alertmanager"
level=info msg="Collecting alerts and silences" alertmanager=local
level=info msg="GET request" timeout=10 uri=https://127.0.0.1:9093/metrics
level=error msg="Request failed" error="Get \"https://127.0.0.1:9093/metrics\": dial tcp 127.0.0.1:9093: connect: connection refused" alertmanager=local uri=https://127.0.0.1:9093
level=error msg="Collection failed" error="Get \"https://127.0.0.1:9093/api/v2/silences\": dial tcp 127.0.0.1:9093: connect: connection refused" alertmanager=local
level=info msg="Collection completed"
level=info msg="Done, starting HTTP server"
level=info msg="Starting HTTPS server" address=127.0.0.1:8087
level=info msg="Shutting down HTTP server"
level=error msg="HTTPS server startup error" error="http: Server closed"
level=info msg="HTTP server shut down"
level=info msg="Removing PID file" path=karma.pid
-- karma.yaml --
alertmanager:
  servers:
    - name: local
      uri: https://127.0.0.1:9093
      timeout: 10s
listen:
  tls:
    cert: karma.pem
    key: karma.key

-- test.sh --
while [ ! -f karma.pid ]; do sleep 1 ; done
sleep 1
curl -s --cacert karma-ca.pem -o http1.txt --http1.1 https://127.0.0.1:8087/health
curl -s --cacert karma-ca.pem -o http2.txt --http2 https://127.0.0.1:8087/health
cat karma.pid | xargs kill
