zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/test/blackbox/helpers_zot.bash (about) 1 ROOT_DIR=$(git rev-parse --show-toplevel) 2 OS=$(go env GOOS) 3 ARCH=$(go env GOARCH) 4 ZOT_PATH=${ROOT_DIR}/bin/zot-${OS}-${ARCH} 5 ZLI_PATH=${ROOT_DIR}/bin/zli-${OS}-${ARCH} 6 ZOT_MINIMAL_PATH=${ROOT_DIR}/bin/zot-${OS}-${ARCH}-minimal 7 ZB_PATH=${ROOT_DIR}/bin/zb-${OS}-${ARCH} 8 TEST_DATA_DIR=${BATS_FILE_TMPDIR}/test/data 9 AUTH_USER=poweruser 10 AUTH_PASS=sup*rSecr9T 11 12 mkdir -p ${TEST_DATA_DIR} 13 14 function get_free_port(){ 15 while true 16 do 17 random_port=$(( ((RANDOM<<15)|RANDOM) % 49152 + 10000 )) 18 status="$(nc -z 127.0.0.1 $random_port < /dev/null &>/dev/null; echo $?)" 19 if [ "${status}" != "0" ]; then 20 free_port=${random_port}; 21 break; 22 fi 23 done 24 25 echo ${free_port} 26 } 27 28 function zot_serve() { 29 local zot_path=${1} 30 local config_file=${2} 31 ${zot_path} serve ${config_file} & 32 # zot.pid file keeps a list of zot server PIDs (in case multiple zot servers are started) 33 echo -n "$! " >> ${BATS_FILE_TMPDIR}/zot.pid 34 } 35 36 # stops all zot instances started by the test 37 function zot_stop_all() { 38 kill $(cat ${BATS_FILE_TMPDIR}/zot.pid) 39 } 40 41 function wait_zot_reachable() { 42 local zot_port=${1} 43 local zot_url=http://127.0.0.1:${zot_port}/v2/_catalog 44 curl --connect-timeout 3 \ 45 --max-time 3 \ 46 --retry 10 \ 47 --retry-delay 0 \ 48 --retry-max-time 120 \ 49 --retry-connrefused \ 50 ${zot_url} 51 } 52 53 function zli_add_config() { 54 local registry_name=${1} 55 local registry_url=${2} 56 # Clean up old configuration for the same registry 57 if ${ZLI_PATH} config --list | grep -q ${registry_name}; then 58 ${ZLI_PATH} config remove ${registry_name} 59 fi 60 # Add the new registry 61 ${ZLI_PATH} config add ${registry_name} ${registry_url} 62 } 63 64 function zb_run() { 65 local zot_address=${1} 66 ${ZB_PATH} -c 10 -n 30 -o stdout ${zot_address} --skip-cleanup 67 }