#!/bin/sh -e

# This is documented here:
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines

. coverage-entrypoint-func.sh

if ! whoami &>/dev/null; then
  if [ -w /etc/passwd ]; then
    echo "${USER_NAME:-klusterlet-addon-controller}:x:$(id -u):$(id -g):${USER_NAME:-klusterlet-addon-controller} user:${HOME}:/sbin/nologin" >> /etc/passwd
  fi
fi

#exec ${OPERATOR}-coverage -test.run "^TestRunMain$" -test.coverprofile=/tmp/coverage/$HOSTNAME-`date +%s%N`.out $@

FILENAME=$HOSTNAME-`date +%s%N`.out
FILEPATH=/tmp/coverage/$FILENAME
mkdir -p /tmp/coverage

${OPERATOR}-coverage -test.run "^TestRunMain$" -test.coverprofile=$FILEPATH $@ & PID=$!

trap_with_arg func_trap 15 $PID $FILENAME $FILEPATH

wait $PID