From 3986d74e10e8ead38145577bd1d11d97c44879dc Mon Sep 17 00:00:00 2001 From: Luke McCrone Date: Mon, 18 Mar 2024 11:11:17 -0300 Subject: [PATCH] test: mc multipart upload, test coverage --- .github/workflows/system.yml | 7 ++++++- tests/setup.sh | 25 ++++++++++++++----------- tests/setup_mc.sh | 3 ++- tests/test_common.sh | 26 ++++++++++++++++++++++++++ tests/test_mc.sh | 6 ++++++ tests/test_s3cmd.sh | 17 +++-------------- 6 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.github/workflows/system.yml b/.github/workflows/system.yml index f431296..3f3f21e 100644 --- a/.github/workflows/system.yml +++ b/.github/workflows/system.yml @@ -51,4 +51,9 @@ jobs: export WORKSPACE=$GITHUB_WORKSPACE openssl genpkey -algorithm RSA -out versitygw.pem -pkeyopt rsa_keygen_bits:2048 openssl req -new -x509 -key versitygw.pem -out cert.pem -days 365 -subj "/C=US/ST=California/L=San Francisco/O=Versity/OU=Software/CN=versity.com" - VERSITYGW_TEST_ENV=./tests/.env.default ./tests/run_all.sh + mkdir /tmp/cover + VERSITYGW_TEST_ENV=./tests/.env.default GOCOVERDIR=/tmp/cover ./tests/run_all.sh + + - name: Coverage report + run: | + go tool covdata percent -i=/tmp/cover diff --git a/tests/setup.sh b/tests/setup.sh index e4c28e0..537a0c4 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -17,22 +17,25 @@ setup() { return 1 fi - S3CMD_OPTS=() - S3CMD_OPTS+=(-c "$S3CMD_CONFIG") - S3CMD_OPTS+=(--access_key="$AWS_ACCESS_KEY_ID") - S3CMD_OPTS+=(--secret_key="$AWS_SECRET_ACCESS_KEY") + if [[ $RUN_S3CMD == true ]]; then + S3CMD_OPTS=() + S3CMD_OPTS+=(-c "$S3CMD_CONFIG") + S3CMD_OPTS+=(--access_key="$AWS_ACCESS_KEY_ID") + S3CMD_OPTS+=(--secret_key="$AWS_SECRET_ACCESS_KEY") + export S3CMD_CONFIG S3CMD_OPTS + fi - check_add_mc_alias || check_result=$? - if [[ $check_result -ne 0 ]]; then - echo "mc alias check/add failed" - return 1 + if [[ $RUN_MC == true ]]; then + check_add_mc_alias || check_result=$? + if [[ $check_result -ne 0 ]]; then + echo "mc alias check/add failed" + return 1 + fi fi export AWS_PROFILE \ BUCKET_ONE_NAME \ - BUCKET_TWO_NAME \ - S3CMD_CONFIG \ - S3CMD_OPTS + BUCKET_TWO_NAME } # make sure required environment variables for tests are defined properly diff --git a/tests/setup_mc.sh b/tests/setup_mc.sh index fee7438..3e9c468 100644 --- a/tests/setup_mc.sh +++ b/tests/setup_mc.sh @@ -8,7 +8,8 @@ check_for_alias() { return 2 fi while IFS= read -r line; do - if [[ $line =~ ^"$MC_ALIAS"$ ]]; then + error=$(echo "$line" | grep -w "$MC_ALIAS ") + if [[ $? -eq 0 ]]; then return 0 fi done <<< "$aliases" diff --git a/tests/test_common.sh b/tests/test_common.sh index 9a1e5d2..f05c86b 100644 --- a/tests/test_common.sh +++ b/tests/test_common.sh @@ -192,6 +192,12 @@ test_common_set_get_bucket_tags() { } test_common_set_get_object_tags() { + + if [[ $# -ne 1 ]]; then + echo "get/set object tags missing command type" + return 1 + fi + local bucket_file="bucket-file" local key="test_key" local value="test_value" @@ -230,3 +236,23 @@ test_common_set_get_object_tags() { delete_bucket_or_contents "$1" "$BUCKET_ONE_NAME" delete_test_files $bucket_file } + +test_common_multipart_upload() { + if [[ $# -ne 1 ]]; then + echo "multipart upload command missing command type" + return 1 + fi + bucket_file="largefile" + + create_large_file "$bucket_file" || local created=$? + [[ $created -eq 0 ]] || fail "Error creating test file for multipart upload" + + setup_bucket "$1" "$BUCKET_ONE_NAME" || local result=$? + [[ $result -eq 0 ]] || fail "Failed to create bucket '$BUCKET_ONE_NAME'" + + put_object "$1" "$test_file_folder"/$bucket_file "$BUCKET_ONE_NAME/$bucket_file" || local put_result=$? + [[ $put_result -eq 0 ]] || fail "failed to copy file" + + delete_bucket_or_contents "$1" "$BUCKET_ONE_NAME" + delete_test_files $bucket_file +} diff --git a/tests/test_mc.sh b/tests/test_mc.sh index 2a3f216..3c95001 100755 --- a/tests/test_mc.sh +++ b/tests/test_mc.sh @@ -3,6 +3,8 @@ source ./tests/test_common.sh source ./tests/setup.sh +export RUN_MC=true + # test mc bucket creation/deletion @test "test_create_delete_bucket_mc" { test_common_create_delete_bucket "mc" @@ -31,3 +33,7 @@ source ./tests/setup.sh @test "test_set_get_object_tags_mc" { test_common_set_get_object_tags "mc" } + +@test "test_multipart_upload_mc" { + test_common_multipart_upload "mc" +} diff --git a/tests/test_s3cmd.sh b/tests/test_s3cmd.sh index d0f48b1..f101d4e 100755 --- a/tests/test_s3cmd.sh +++ b/tests/test_s3cmd.sh @@ -4,6 +4,8 @@ source ./tests/setup.sh source ./tests/test_common.sh source ./tests/util.sh +export RUN_S3CMD=true + # test s3cmd bucket creation/deletion @test "test_create_delete_bucket_s3cmd" { test_common_create_delete_bucket "s3cmd" @@ -28,18 +30,5 @@ source ./tests/util.sh } @test "test_multipart_upload_s3cmd" { - - bucket_file="largefile" - - create_large_file "$bucket_file" || local created=$? - [[ $created -eq 0 ]] || fail "Error creating test file for multipart upload" - - setup_bucket "s3cmd" "$BUCKET_ONE_NAME" || local result=$? - [[ $result -eq 0 ]] || fail "Failed to create bucket '$BUCKET_ONE_NAME'" - - put_object "s3cmd" "$test_file_folder"/$bucket_file "$BUCKET_ONE_NAME/$bucket_file" || local put_result=$? - [[ $put_result -eq 0 ]] || fail "failed to copy file" - - delete_bucket_or_contents "s3cmd" "$BUCKET_ONE_NAME" - delete_test_files $bucket_file + test_common_multipart_upload "s3cmd" } \ No newline at end of file