#!/bin/sh

SAMPLE_FILE="debian/tests/files/logswan.log"
PROTOCOLS_FILE="debian/tests/files/protocols_expected.txt"
TMP_OUTPUT_FILE="$AUTOPKGTEST_TMP/output.json"
TMP_PROTOCOLS_OUTPUT_FILE="$AUTOPKGTEST_TMP/protocols_out.txt"

logswan $SAMPLE_FILE > $TMP_OUTPUT_FILE

GET_HITS=$(jq '.methods[] | select(.data=="GET") | .hits' $TMP_OUTPUT_FILE)
test "$GET_HITS" -eq 66

HEAD_HITS=$(jq '.methods[] | select(.data=="HEAD") | .hits' $TMP_OUTPUT_FILE)
test "$HEAD_HITS" -eq 2

jq '.protocols[] | .data' $TMP_OUTPUT_FILE > $TMP_PROTOCOLS_OUTPUT_FILE
cmp "$TMP_PROTOCOLS_OUTPUT_FILE" "$PROTOCOLS_FILE"
