#!/bin/bash

set -ex

function stop_docker()
{
  echo "stopping arc_vector_test"
  docker stop arc_vector_test
}

# Ensure current path is project root
cd "$(dirname "$0")/../"

ARC_VECTOR_VERSION='v1.4.0'

ARC_VECTOR_HOST='localhost:6333'

docker run -d --rm \
           --network=host \
           --name arc_vector_test arc_vector/arc_vector:${ARC_VECTOR_VERSION}

trap stop_docker SIGINT
trap stop_docker ERR

until curl --output /dev/null --silent --get --fail http://$ARC_VECTOR_HOST/collections; do
  printf 'waiting for server to start...'
  sleep 5
done

cargo test --all

echo "Ok, that is enough"

stop_docker
