From 49b717da6ddb6ae7212b5e6a98f2a12ca3794048 Mon Sep 17 00:00:00 2001 From: moooofly Date: Wed, 4 Jul 2018 20:04:00 +0800 Subject: [PATCH 1/2] feat: optimize 'make test' --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a5a3e00..decb37a 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ ifeq "$(GOPATH)" "" endif GO := go +PKGS := $(shell $(GO) list ./... | grep -v vendor) GOBUILD := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG) LDFLAGS += -X "github.com/moooofly/harbor-go-client/utils.ClientVersion=$(shell cat VERSION)" @@ -31,7 +32,7 @@ lint: test: @echo "==> Testing ..." - $(GO) test ${SRC} + $(GO) test -short -race $(PKGS) pack: build @echo "==> Packing ..." From 1bc2d9f53463ef038afca6bf90ec303f0d97af28 Mon Sep 17 00:00:00 2001 From: moooofly Date: Thu, 5 Jul 2018 10:51:30 +0800 Subject: [PATCH 2/2] feat: update *.sh according to shellcheck --- Makefile | 4 + scripts/regression_test.sh | 198 ++++++++++++++++----------------- scripts/rp_repos_simulation.sh | 28 ++--- 3 files changed, 117 insertions(+), 113 deletions(-) diff --git a/Makefile b/Makefile index decb37a..54ae3cc 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,10 @@ misspell: # go get -u github.com/client9/misspell/cmd/misspell find . -name '*.go' -not -path './vendor/*' -not -path './_repos/*' | xargs misspell -error +shellcheck: + # apt-get install -y shellcheck + shellcheck ./scripts/*.sh + clean: @echo "==> Cleaning ..." $(GO) clean -x -i ${SRC} diff --git a/scripts/regression_test.sh b/scripts/regression_test.sh index 1d1d26f..de09f4a 100755 --- a/scripts/regression_test.sh +++ b/scripts/regression_test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e @@ -13,7 +13,7 @@ prepare() { echo "----- prepare harbor-go-client and conf/ for tesing -----" go build -v ../ cp -r ../conf . - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- docker login -----" docker login --username admin --password Harbor12345 $HARBOR_ADDR @@ -23,48 +23,48 @@ prepare() { docker pull hello-world for i in $(seq 1 5) do - docker tag hello-world:latest $HARBOR_ADDR/$PRJ_NAME/hello-world:v$i + docker tag hello-world:latest $HARBOR_ADDR/$PRJ_NAME/hello-world:v"$i" done - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- harbor-go-client login -----" - ./harbor-go-client login -u admin -p Harbor12345 && echo "${SUCCESS} username: admin\n${SUCCESS} Save .cookie.yaml" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client login -u admin -p Harbor12345 && echo -e "${SUCCESS} username: admin\n${SUCCESS} Save .cookie.yaml" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- whoami -----" ./harbor-go-client whoami && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- prj_create (--public=1) -----" - ./harbor-go-client prj_create --project_name=$PRJ_NAME --public=1 && echo "${SUCCESS} project_name: $PRJ_NAME\n${SUCCESS} public" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_create --project_name=$PRJ_NAME --public=1 && echo -e "${SUCCESS} project_name: $PRJ_NAME\n${SUCCESS} public" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- push repo and tags under $PRJ_NAME project -----" for i in $(seq 1 5) do - docker push $HARBOR_ADDR/$PRJ_NAME/hello-world:v$i + docker push $HARBOR_ADDR/$PRJ_NAME/hello-world:v"$i" done - echo "-----------------\n\n" + printf "-----------------\n\n" } cleanup() { echo "----- harbor-go-client logout -----" ./harbor-go-client logout && echo "${SUCCESS} Delete .cookie.yaml" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- delete docker image and tags created for test -----" - docker rmi -f $(docker images hello-world -q) - echo "-----------------\n\n" + docker rmi -f "$(docker images hello-world -q)" + printf "-----------------\n\n" echo "----- docker logout -----" docker logout $HARBOR_ADDR - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- remove harbor-go-client and conf/ -----" rm harbor-go-client rm -r conf/ - echo "-----------------\n\n" + printf "-----------------\n\n" } full_api_tests() { @@ -79,127 +79,127 @@ full_api_tests() { echo "----- prjs_list (filter by --name=$PRJ_NAME) -----" ./harbor-go-client prjs_list --name=$PRJ_NAME && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" PRJ_ID=$(./harbor-go-client prjs_list --name=$PRJ_NAME | grep "project_id" | awk '{print $2}' | sed -r 's/,//g') echo "----- prj_get (--project_id=$PRJ_ID) -----" - ./harbor-go-client prj_get --project_id=$PRJ_ID && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_get --project_id="$PRJ_ID" && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- repos_list (under project $PRJ_ID, filter by $PRJ_NAME) -----" - ./harbor-go-client repos_list --project_id=$PRJ_ID --repo_name=$PRJ_NAME && echo "${SUCCESS} project_id: $PRJ_ID\n${SUCCESS} repo_name (filter): $PRJ_NAME" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client repos_list --project_id="$PRJ_ID" --repo_name=$PRJ_NAME && echo -e "${SUCCESS} project_id: $PRJ_ID\n${SUCCESS} repo_name (filter): $PRJ_NAME" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- tags_list -----" ./harbor-go-client tags_list --repo_name=$PRJ_NAME/hello-world && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- tag_get -----" for i in $(seq 1 5) do - ./harbor-go-client tag_get --repo_name=$PRJ_NAME/hello-world --tag=v$i && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" + ./harbor-go-client tag_get --repo_name="$PRJ_NAME"/hello-world --tag=v"$i" && echo -e "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" done - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- search -----" ./harbor-go-client search --query=$PRJ_NAME && echo "${SUCCESS} query: $PRJ_NAME" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- tag_del -----" for i in $(seq 1 5) do - ./harbor-go-client tag_del --repo_name=$PRJ_NAME/hello-world --tag=v$i && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" + ./harbor-go-client tag_del --repo_name=$PRJ_NAME/hello-world --tag=v"$i" && echo -e "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" done - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- repo_del -----" echo "----- (NOTE: if all tags with a repo are deleted, the repo will be deleted altogether. You will get 404 NOT FOUND here) -----" ./harbor-go-client repo_del --repo_name=$PRJ_NAME/hello-world && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- prj_del -----" - ./harbor-go-client prj_del --project_id=$PRJ_ID && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_del --project_id="$PRJ_ID" && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" + printf "-----------------\n\n" # special one echo "----- repos_top -----" ./harbor-go-client repos_top --count=3 && echo "${SUCCESS} count: 3" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" # ---- echo "----- targets_create -----" - ./harbor-go-client targets_create --endpoint=11.11.11.100 --name=e100 -u admin -p Harbor12345 --insecure && echo "${SUCCESS} endpoint: 11.11.11.100\n${SUCCESS} name: e100" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client targets_create --endpoint=11.11.11.100 --name=e100 -u admin -p Harbor12345 --insecure && echo -e "${SUCCESS} endpoint: 11.11.11.100\n${SUCCESS} name: e100" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- targets_list -----" ./harbor-go-client targets_list --name=100 && echo "${SUCCESS} name (filter): 100" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" TARGET_ID=$(./harbor-go-client targets_list --name=100 | grep "id" | awk '{print $2}' | sed 's/,//g') echo "----- targets_update_by_tid -----" - ./harbor-go-client targets_update_by_tid --id=$TARGET_ID --endpoint=11.11.11.100 --name="from e100 to E100" -u admin -p Harbor12345 --insecure && echo "${SUCCESS} id: $TARGET_ID\n${SUCCESS} name: from e100 to E100" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client targets_update_by_tid --id="$TARGET_ID" --endpoint=11.11.11.100 --name="from e100 to E100" -u admin -p Harbor12345 --insecure && echo -e "${SUCCESS} id: $TARGET_ID\n${SUCCESS} name: from e100 to E100" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- targets_get_by_tid -----" - ./harbor-go-client targets_get_by_tid --id=$TARGET_ID && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client targets_get_by_tid --id="$TARGET_ID" && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- targets_policies_by_tid -----" - ./harbor-go-client targets_policies_by_tid --id=$TARGET_ID && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client targets_policies_by_tid --id="$TARGET_ID" && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- targets_ping (Not working here, just show how to use) -----" ./harbor-go-client targets_ping --endpoint=11.11.11.100 -u admin -p Harbor12345 --insecure && echo "${SUCCESS} endpoint: 11.11.11.100" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- targets_ping_by_tid (Not working here, just show how to use) -----" - ./harbor-go-client targets_ping_by_tid --id=$TARGET_ID && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client targets_ping_by_tid --id="$TARGET_ID" && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- targets_delete_by_tid -----" - ./harbor-go-client targets_delete_by_tid --id=$TARGET_ID && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client targets_delete_by_tid --id="$TARGET_ID" && echo "${SUCCESS} id: $TARGET_ID" || echo "${ERROR}" + printf "-----------------\n\n" # ---- echo "----- configurations_create (read system configuration from conf/config.yaml) -----" ./harbor-go-client configurations_create && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- configurations_get -----" ./harbor-go-client configurations_get && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- configurations_reset (reset to default setting) -----" ./harbor-go-client configurations_reset && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" # ---- echo "----- sysinfo_general -----" ./harbor-go-client sysinfo_general && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- sysinfo_volumes -----" ./harbor-go-client sysinfo_volumes && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- sysinfo_rootcert (You will get 404 NOT FOUND here) -----" ./harbor-go-client sysinfo_rootcert && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" # ---- echo "----- logs -----" ./harbor-go-client logs && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- statistics -----" ./harbor-go-client statistics && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" cleanup } @@ -217,15 +217,15 @@ repositories_test() { echo "----- repo_del -----" ./harbor-go-client repo_del --repo_name=$PRJ_NAME/hello-world && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- repo_del (one more time, you will get 404 NOT FOUND) -----" ./harbor-go-client repo_del --repo_name=$PRJ_NAME/hello-world && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- repos_top -----" ./harbor-go-client repos_top --count=3 && echo "${SUCCESS} count: 3" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" cleanup } @@ -242,31 +242,31 @@ tags_test() { echo "----- tags_list -----" ./harbor-go-client tags_list --repo_name=$PRJ_NAME/hello-world && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" # get echo "----- tag_get -----" for i in $(seq 1 5) do - ./harbor-go-client tag_get --repo_name=$PRJ_NAME/hello-world --tag=v$i && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" + ./harbor-go-client tag_get --repo_name=$PRJ_NAME/hello-world --tag=v"$i" && echo -e "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" done - echo "-----------------\n\n" + printf "-----------------\n\n" # del echo "----- tag_del -----" for i in $(seq 1 5) do - ./harbor-go-client tag_del --repo_name=$PRJ_NAME/hello-world --tag=v$i && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" + ./harbor-go-client tag_del --repo_name=$PRJ_NAME/hello-world --tag=v"$i" && echo -e "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" done - echo "-----------------\n\n" + printf "-----------------\n\n" # get again echo "----- tag_get (You will get 404 NOT FOUND here) -----" for i in $(seq 1 5) do - ./harbor-go-client tag_get --repo_name=$PRJ_NAME/hello-world --tag=v$i && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" + ./harbor-go-client tag_get --repo_name=$PRJ_NAME/hello-world --tag=v"$i" && echo -e "${SUCCESS} repo_name: $PRJ_NAME/hello-world\n${SUCCESS} tag: v$i" || echo "${ERROR}" done - echo "-----------------\n\n" + printf "-----------------\n\n" cleanup } @@ -282,67 +282,67 @@ projects_test() { prepare echo "----- prj_create (--public=1) -----" - ./harbor-go-client prj_create --project_name=${PRJ_NAME}-public --public=1 && echo "${SUCCESS} project_name: ${PRJ_NAME}-public\n${SUCCESS} public" || echo "${ERROR}" - echo "-----------------\n" + ./harbor-go-client prj_create --project_name=${PRJ_NAME}-public --public=1 && echo -e "${SUCCESS} project_name: ${PRJ_NAME}-public\n${SUCCESS} public" || echo "${ERROR}" + printf "-----------------\n" echo "----- prj_create (--public=0) -----" - ./harbor-go-client prj_create --project_name=${PRJ_NAME}-private --public=0 && echo "${SUCCESS} project_name: ${PRJ_NAME}-private\n${SUCCESS} private" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_create --project_name=${PRJ_NAME}-private --public=0 && echo -e "${SUCCESS} project_name: ${PRJ_NAME}-private\n${SUCCESS} private" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- prjs_list (--public=1) -----" - ./harbor-go-client prjs_list --name=${PRJ_NAME}-public --public=1 && echo "${SUCCESS} name (filter): ${PRJ_NAME}-public\n${SUCCESS} public" || echo "${ERROR}" - echo "-----------------\n" + ./harbor-go-client prjs_list --name=${PRJ_NAME}-public --public=1 && echo -e "${SUCCESS} name (filter): ${PRJ_NAME}-public\n${SUCCESS} public" || echo "${ERROR}" + printf "-----------------\n" echo "----- prjs_list (--public=0) -----" - ./harbor-go-client prjs_list --name=${PRJ_NAME}-private --public=0 && echo "${SUCCESS} name (filter): ${PRJ_NAME}-private\n${SUCCESS} private" || echo "${ERROR}" - echo "-----------------\n" + ./harbor-go-client prjs_list --name=${PRJ_NAME}-private --public=0 && echo -e "${SUCCESS} name (filter): ${PRJ_NAME}-private\n${SUCCESS} private" || echo "${ERROR}" + printf "-----------------\n" echo "----- prjs_list (--public=) -----" - ./harbor-go-client prjs_list --name=${PRJ_NAME} && echo "${SUCCESS} name (filter): ${PRJ_NAME}\n${SUCCESS} public + private" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prjs_list --name=${PRJ_NAME} && echo -e "${SUCCESS} name (filter): ${PRJ_NAME}\n${SUCCESS} public + private" || echo "${ERROR}" + printf "-----------------\n\n" PUB_ID=$(./harbor-go-client prjs_list --name=${PRJ_NAME}-public --public=1 | grep "project_id" | awk '{print $2}' | sed 's/,//g') PRI_ID=$(./harbor-go-client prjs_list --name=${PRJ_NAME}-private --public=0 | grep "project_id" | awk '{print $2}' | sed 's/,//g') echo "----- prj_get (--project_id=$PUB_ID, before delete) -----" - ./harbor-go-client prj_get --project_id=$PUB_ID && echo "${SUCCESS} project_id: $PUB_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_get --project_id="$PUB_ID" && echo "${SUCCESS} project_id: $PUB_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- prj_get (--project_id=$PRI_ID, before delete) -----" - ./harbor-go-client prj_get --project_id=$PRI_ID && echo "${SUCCESS} project_id: $PRI_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_get --project_id="$PRI_ID" && echo "${SUCCESS} project_id: $PRI_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- prj_del (--project_id=$PUB_ID, public) -----" - ./harbor-go-client prj_del --project_id=$PUB_ID && echo "${SUCCESS} project_id: $PUB_ID\n${SUCCESS} public" || echo "${ERROR}" - echo "-----------------\n" + ./harbor-go-client prj_del --project_id="$PUB_ID" && echo -e "${SUCCESS} project_id: $PUB_ID\n${SUCCESS} public" || echo "${ERROR}" + printf "-----------------\n" echo "----- prj_del (--project_id=$PRI_ID, private) -----" - ./harbor-go-client prj_del --project_id=$PRI_ID && echo "${SUCCESS} project_id: $PRI_ID\n${SUCCESS} private" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_del --project_id="$PRI_ID" && echo -e "${SUCCESS} project_id: $PRI_ID\n${SUCCESS} private" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- prj_get (--project_id=$PUB_ID, after delete) -----" - ./harbor-go-client prj_get --project_id=$PUB_ID && echo "${SUCCESS} project_id: $PUB_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_get --project_id="$PUB_ID" && echo "${SUCCESS} project_id: $PUB_ID" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- prj_get (--project_id=$PRI_ID, after delete) -----" - ./harbor-go-client prj_get --project_id=$PRI_ID && echo "${SUCCESS} project_id: $PRI_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_get --project_id="$PRI_ID" && echo "${SUCCESS} project_id: $PRI_ID" || echo "${ERROR}" + printf "-----------------\n\n" PRJ_ID=$(./harbor-go-client prjs_list --name=$PRJ_NAME | grep "project_id" | awk '{print $2}' | sed -r 's/,//g') echo "----- prj_del (project contains repositories, cann't be deleled, will get 412 Precondition Failed) -----" - ./harbor-go-client prj_del --project_id=$PRJ_ID && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_del --project_id="$PRJ_ID" && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" + printf "-----------------\n\n" #echo "----- prj_del (project contains targets, cann't be deleled, will get 412 Precondition Failed) -----" echo "----- repo_del (delete the repo under project $PRJ_NAME)-----" ./harbor-go-client repo_del --repo_name=$PRJ_NAME/hello-world && echo "${SUCCESS} repo_name: $PRJ_NAME/hello-world" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- prj_del (project contains no repositories, can be deleled this time) -----" - ./harbor-go-client prj_del --project_id=$PRJ_ID && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client prj_del --project_id="$PRJ_ID" && echo "${SUCCESS} project_id: $PRJ_ID" || echo "${ERROR}" + printf "-----------------\n\n" cleanup } @@ -352,24 +352,24 @@ users_test() { echo "----- prepare harbor-go-client and conf/ for tesing -----" go build -v ../ cp -r ../conf . - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- harbor-go-client login -----" - ./harbor-go-client login -u admin -p Harbor12345 && echo "${SUCCESS} username: admin\n${SUCCESS} Save .cookie.yaml" || echo "${ERROR}" - echo "-----------------\n\n" + ./harbor-go-client login -u admin -p Harbor12345 && echo -e "${SUCCESS} username: admin\n${SUCCESS} Save .cookie.yaml" || echo "${ERROR}" + printf "-----------------\n\n" echo "----- whoami -----" ./harbor-go-client whoami && echo "${SUCCESS}" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- logout -----" ./harbor-go-client logout && echo "${SUCCESS} Delete .cookie.yaml" || echo "${ERROR}" - echo "-----------------\n\n" + printf "-----------------\n\n" echo "----- remove harbor-go-client and conf/ -----" rm harbor-go-client rm -r conf/ - echo "-----------------\n\n" + printf "-----------------\n\n" } retention_policy_test() { @@ -381,7 +381,7 @@ retention_policy_test() { echo ./rp_repos_simulation.sh 10 10 10 - echo "-----------------\n\n" + printf "-----------------\n\n" } scenario_simulation_tests() { @@ -427,7 +427,7 @@ echo "2. Run Scenario Simulation tests on you choose." echo read -p "Please select which one do you prefer: [1] " OPTION -if [ -z $OPTION ] ; then +if [ -z "$OPTION" ] ; then echo "Selecting default: 1" OPTION=1 elif [ $OPTION -eq 1 ] ; then @@ -444,7 +444,7 @@ elif [ $OPTION -eq 2 ] ; then echo "9. all scenarios" echo read -p "Please select which scenario do you prefer: [1] " SCENARIO - if [ -z $SCENARIO ] ; then + if [ -z "$SCENARIO" ] ; then SCENARIO=1 fi echo "You select: $SCENARIO" diff --git a/scripts/rp_repos_simulation.sh b/scripts/rp_repos_simulation.sh index bd508b2..84134b8 100755 --- a/scripts/rp_repos_simulation.sh +++ b/scripts/rp_repos_simulation.sh @@ -37,14 +37,14 @@ retention_policy_test() { # 1. create $PRJS_NUM projects for test echo -e "$L1 --> create $PRJS_NUM projects for test $END" echo - for (( i=1; i<=$PRJS_NUM; i++ )) + for (( i=1; i<=PRJS_NUM; i++ )) do # create both public and private projects - if (( i % 2 == 0 )) ; then - PUBLIC=1 - else - PUBLIC=0 - fi + #if (( i % 2 == 0 )) ; then + # PUBLIC=1 + #else + # PUBLIC=0 + #fi echo #echo -e "$L2 ----> create: project_name=${PROJECT_NAME}_$i public=${PUBLIC} $END" @@ -53,7 +53,7 @@ retention_policy_test() { #./harbor-go-client prj_create --project_name="${PROJECT_NAME}_$i" --public=${PUBLIC} ./harbor-go-client prj_create --project_name="${PROJECT_NAME}_$i" --public=1 - rands=$((RANDOM % $TAGS_NUM)) + rands=$((RANDOM % TAGS_NUM)) echo echo -e "$L2 ----> generate a random number ($rands) of tags and push onto Harbor $END" echo @@ -61,16 +61,16 @@ retention_policy_test() { for r in $(seq $rands) do # 2. create tags, push repos and tags - docker tag hello-world:latest ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v${r} - docker push ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v${r} >/dev/null && echo "docker push ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v${r}" || echo "Failed" + docker tag hello-world:latest ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v"$r" + docker push "${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v$r" >/dev/null && echo "docker push ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v${r}" || echo "Failed" # 3. make a random number of pull - loop=$((RANDOM % $PULL_NUM)) + loop=$((RANDOM % PULL_NUM)) echo -e "$L3 ----> pull ${PROJECT_NAME}_${i}/hello-world:v${r} random times ($loop) $END" echo - for j in $(seq $loop) + for _ in $(seq $loop) do - docker pull ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v${r} >/dev/null + docker pull ${HARBOR_ADDR}/${PROJECT_NAME}_${i}/hello-world:v"$r" >/dev/null done done done @@ -97,14 +97,14 @@ retention_policy_test() { IDS=$(./harbor-go-client prjs_list --name=${PROJECT_NAME} | grep "project_id" | awk '{print $2}' | sed -r 's/,//g') for id in $IDS do - ./harbor-go-client prj_del --project_id=${id} + ./harbor-go-client prj_del --project_id="$id" echo done # 7. delete local docker tags and images echo -e "$L1 --> delete all tags and images created locally $END" echo - docker rmi -f $(docker images hello-world -q) + docker rmi -f "$(docker images hello-world -q)" } prepare() {