#!/bin/bash
set -e

stubby -C $(dirname $0)/stubby.yml &
port=5533
error=0
counter=0

# a simple smoke test just make sure that at least one query can go through:
sleep 0.1
PID=$(ps x|grep stubby.yml|grep -v grep|cut -d" " -f1)
echo PID of stubby: $PID
time for i in {0..9}; do
  if diff -u <(kdig +short @::1@$port getdnsapi.net) <(echo 185.49.141.37); then
    printf .
  else
    printf !
    error=$((error+1))
  fi
  counter=$((counter+1))
done

[ -n "$PID" ] && kill $PID
echo $error "time(s) error out of $counter times run."
exit $error

# more ideas for better tests?  we want them!  send them to the BTS, please.
