Skip to content

Commit

Permalink
test: static bucket init fix, github-actions enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
lrm25 committed Sep 13, 2024
1 parent 53a7abf commit ae1c566
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 266 deletions.
44 changes: 33 additions & 11 deletions .github/workflows/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
fail-fast: false
matrix:
include:
- set: 1
- set: "s3cmd, posix"
LOCAL_FOLDER: /tmp/gw1
BUCKET_ONE_NAME: versity-gwtest-bucket-one-1
BUCKET_TWO_NAME: versity-gwtest-bucket-two-1
Expand All @@ -19,7 +19,7 @@ jobs:
RECREATE_BUCKETS: "true"
PORT: 7070
BACKEND: "posix"
- set: 2
- set: "s3, posix"
LOCAL_FOLDER: /tmp/gw2
BUCKET_ONE_NAME: versity-gwtest-bucket-one-2
BUCKET_TWO_NAME: versity-gwtest-bucket-two-2
Expand All @@ -30,7 +30,7 @@ jobs:
RECREATE_BUCKETS: "true"
PORT: 7071
BACKEND: "posix"
- set: 3
- set: "s3api, posix"
LOCAL_FOLDER: /tmp/gw3
BUCKET_ONE_NAME: versity-gwtest-bucket-one-3
BUCKET_TWO_NAME: versity-gwtest-bucket-two-3
Expand All @@ -41,7 +41,7 @@ jobs:
RECREATE_BUCKETS: "true"
PORT: 7072
BACKEND: "posix"
- set: 4
- set: "mc, posix"
LOCAL_FOLDER: /tmp/gw4
BUCKET_ONE_NAME: versity-gwtest-bucket-one-4
BUCKET_TWO_NAME: versity-gwtest-bucket-two-4
Expand All @@ -52,40 +52,40 @@ jobs:
RECREATE_BUCKETS: "true"
PORT: 7073
BACKEND: "posix"
- set: 5
- set: "s3api-user, posix, s3 IAM"
LOCAL_FOLDER: /tmp/gw5
BUCKET_ONE_NAME: versity-gwtest-bucket-one-5
BUCKET_TWO_NAME: versity-gwtest-bucket-two-5
IAM_TYPE: s3
USERS_BUCKET: versity-gwtest-iam
AWS_ENDPOINT_URL: https://127.0.0.1:7074
RUN_SET: "aws-user"
RUN_SET: "s3api-user"
RECREATE_BUCKETS: "true"
PORT: 7074
BACKEND: "posix"
- set: 6
- set: "s3api non-policy, static buckets"
LOCAL_FOLDER: /tmp/gw6
BUCKET_ONE_NAME: versity-gwtest-bucket-one-6
BUCKET_TWO_NAME: versity-gwtest-bucket-two-6
IAM_TYPE: folder
USERS_FOLDER: /tmp/iam6
AWS_ENDPOINT_URL: https://127.0.0.1:7075
RUN_SET: "aws"
RUN_SET: "s3api-non-policy"
RECREATE_BUCKETS: "false"
PORT: 7075
BACKEND: "posix"
- set: 7
- set: "s3api, s3 backend"
LOCAL_FOLDER: /tmp/gw7
BUCKET_ONE_NAME: versity-gwtest-bucket-one-7
BUCKET_TWO_NAME: versity-gwtest-bucket-two-7
IAM_TYPE: folder
USERS_FOLDER: /tmp/iam7
AWS_ENDPOINT_URL: https://127.0.0.1:7076
RUN_SET: "aws"
RUN_SET: "s3api"
RECREATE_BUCKETS: "true"
PORT: 7076
BACKEND: "s3"
- set: 8
- set: "REST, posix"
LOCAL_FOLDER: /tmp/gw8
BUCKET_ONE_NAME: versity-gwtest-bucket-one-7
BUCKET_TWO_NAME: versity-gwtest-bucket-two-7
Expand All @@ -96,6 +96,28 @@ jobs:
RECREATE_BUCKETS: "true"
PORT: 7077
BACKEND: "posix"
- set: "s3api policy, static buckets"
LOCAL_FOLDER: /tmp/gw9
BUCKET_ONE_NAME: versity-gwtest-bucket-one-8
BUCKET_TWO_NAME: versity-gwtest-bucket-two-8
IAM_TYPE: folder
USERS_FOLDER: /tmp/iam9
AWS_ENDPOINT_URL: https://127.0.0.1:7078
RUN_SET: "s3api-policy"
RECREATE_BUCKETS: "false"
PORT: 7078
BACKEND: "posix"
- set: "s3api user, static buckets"
LOCAL_FOLDER: /tmp/gw10
BUCKET_ONE_NAME: versity-gwtest-bucket-one-9
BUCKET_TWO_NAME: versity-gwtest-bucket-two-9
IAM_TYPE: folder
USERS_FOLDER: /tmp/iam10
AWS_ENDPOINT_URL: https://127.0.0.1:7079
RUN_SET: "s3api-user"
RECREATE_BUCKETS: "false"
PORT: 7079
BACKEND: "posix"
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
5 changes: 4 additions & 1 deletion tests/commands/head_bucket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ source ./tests/report.sh
head_bucket() {
log 6 "head_bucket"
record_command "head-bucket" "client:$1"
assert [ $# -eq 2 ]
if [ $# -ne 2 ]; then
log 2 "'head_bucket' command requires client, bucket name"
return 1
fi
local exit_code=0
if [[ $1 == "aws" ]] || [[ $1 == 's3api' ]] || [[ $1 == 's3' ]]; then
bucket_info=$(aws --no-verify-ssl s3api head-bucket --bucket "$2" 2>&1) || exit_code=$?
Expand Down
138 changes: 105 additions & 33 deletions tests/env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bats
#!/usr/bin/env bash

# Copyright 2024 Versity Software
# This file is licensed under the Apache License, Version 2.0
Expand All @@ -14,24 +14,32 @@
# specific language governing permissions and limitations
# under the License.

load ./bats-support/load
load ./bats-assert/load
source ./tests/versity.sh

base_setup() {
check_env_vars
if [ "$RUN_VERSITYGW" == "true" ]; then
run_versity_app
fi
}

check_env_vars() {
check_universal_vars
#if ! check_universal_vars; then
# log 2 "error checking universal params"
# return 1
#fi
if [[ $RUN_VERSITYGW == "true" ]]; then
check_versity_vars
fi
if [[ $RUN_S3CMD == "true" ]]; then
assert [ -n "$S3CMD_CONFIG" ]
if [ -z "$S3CMD_CONFIG" ]; then
log 1 "S3CMD_CONFIG param missing"
exit 1
fi
export S3CMD_CONFIG
fi
if [[ $RUN_MC == "true" ]]; then
assert [ -n "$MC_ALIAS" ]
if [ -z "$MC_ALIAS" ]; then
log 1 "MC_ALIAS param missing"
exit 1
fi
export MC_ALIAS
fi
return 0
Expand Down Expand Up @@ -66,37 +74,80 @@ check_universal_vars() {
export LOG_LEVEL_INT=$LOG_LEVEL
fi

assert [ -n "$AWS_ACCESS_KEY_ID" ]
assert [ -n "$AWS_SECRET_ACCESS_KEY" ]
assert [ -n "$AWS_REGION" ]
assert [ -n "$AWS_PROFILE" ]
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
log 1 "AWS_ACCESS_KEY_ID missing"
exit 1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
log 1 "AWS_SECRET_ACCESS_KEY missing"
exit 1
fi
if [ -z "$AWS_REGION" ]; then
log 1 "AWS_REGION missing"
exit 1
fi
if [ -z "$AWS_PROFILE" ]; then
log 1 "AWS_PROFILE missing"
exit 1
fi
if [ "$DIRECT" != "true" ]; then
assert [ -n "$AWS_ENDPOINT_URL" ]
if [ -z "$AWS_ENDPOINT_URL" ]; then
log 1 "AWS_ENDPOINT_URL missing"
exit 1
fi
fi
if [ "$RUN_VERSITYGW" != "true" ] && [ "$RUN_VERSITYGW" != "false" ]; then
fail "RUN_VERSITYGW must be 'true' or 'false'"
fi

assert [ -n "$BUCKET_ONE_NAME" ]
assert [ -n "$BUCKET_TWO_NAME" ]
assert [ -n "$RECREATE_BUCKETS" ]
if [ -z "$BUCKET_ONE_NAME" ]; then
log 1 "BUCKET_ONE_NAME missing"
exit 1
fi
if [ -z "$BUCKET_TWO_NAME" ]; then
log 1 "BUCKET_TWO_NAME missing"
exit 1
fi
if [ -z "$RECREATE_BUCKETS" ]; then
log 1 "RECREATE_BUCKETS missing"
exit 1
fi
if [ "$RECREATE_BUCKETS" != "true" ] && [ "$RECREATE_BUCKETS" != "false" ]; then
fail "RECREATE_BUCKETS must be 'true' or 'false'"
log 1 "RECREATE_BUCKETS must be 'true' or 'false'"
exit 1
fi
if [ -z "$TEST_FILE_FOLDER" ]; then
log 1 "TEST_FILE_FOLDER missing"
exit 1
fi
assert [ -n "$TEST_FILE_FOLDER" ]
# exporting these since they're needed for subshells
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_PROFILE AWS_ENDPOINT_URL
}

check_versity_vars() {
assert [ -n "$LOCAL_FOLDER" ]
assert [ -n "$VERSITY_EXE" ]
assert [ -n "$BACKEND" ]
if [ -z "$LOCAL_FOLDER" ]; then
log 1 "LOCAL_FOLDER missing"
exit 1
fi
if [ -z "$VERSITY_EXE" ]; then
log 1 "VERSITY_EXE missing"
exit 1
fi
if [ -z "$BACKEND" ]; then
log 1 "BACKEND missing"
exit 1
fi
export LOCAL_FOLDER VERSITY_EXE BACKEND

if [ "$BACKEND" == 's3' ]; then
assert [ -n "$AWS_ACCESS_KEY_ID_TWO" ]
assert [ -n "$AWS_SECRET_ACCESS_KEY_TWO" ]
if [ -z "$AWS_ACCESS_KEY_ID_TWO" ]; then
log 1 "AWS_ACCESS_KEY_ID_TWO missing"
exit 1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY_TWO" ]; then
log 1 "AWS_SECRET_ACCESS_KEY_TWO missing"
exit 1
fi
export AWS_ACCESS_KEY_ID_TWO AWS_SECRET_ACCESS_KEY_TWO
fi

Expand All @@ -110,31 +161,52 @@ check_versity_vars() {
}

check_user_vars() {
assert [ -n "$USERNAME_ONE" ]
assert [ -n "$PASSWORD_ONE" ]
assert [ -n "$USERNAME_TWO" ]
assert [ -n "$PASSWORD_TWO" ]
if [ -z "$USERNAME_ONE" ]; then
log 1 "USERNAME_ONE missing"
exit 1
fi
if [ -z "$PASSWORD_ONE" ]; then
log 1 "PASSWORD_ONE missing"
exit 1
fi
if [ -z "$USERNAME_TWO" ]; then
log 1 "USERNAME_TWO missing"
exit 1
fi
if [ -z "$PASSWORD_TWO" ]; then
log 1 "PASSWORD_TWO missing"
exit 1
fi

if [[ -z "$IAM_TYPE" ]]; then
export IAM_TYPE="folder"
fi
if [[ "$IAM_TYPE" == "folder" ]]; then
assert [ -n "$USERS_FOLDER" ]
if [ -z "$USERS_FOLDER" ]; then
log 1 "USERS_FOLDER missing"
exit 1
fi
if [ ! -d "$USERS_FOLDER" ]; then
mkdir_error=$(mkdir "$USERS_FOLDER" 2>&1)
assert_success "error creating users folder: $mkdir_error"
if ! mkdir_error=$(mkdir "$USERS_FOLDER" 2>&1); then
log 1 "error creating users folder: $mkdir_error"
exit 1
fi
fi
IAM_PARAMS="--iam-dir=$USERS_FOLDER"
export IAM_PARAMS
return 0
fi
if [[ $IAM_TYPE == "s3" ]]; then
assert [ -n "$USERS_BUCKET" ]
if [ -z "$USERS_BUCKET" ]; then
log 1 "error creating USERS_BUCKET"
exit 1
fi
IAM_PARAMS="--s3-iam-access $AWS_ACCESS_KEY_ID --s3-iam-secret $AWS_SECRET_ACCESS_KEY \
--s3-iam-region us-east-1 --s3-iam-bucket $USERS_BUCKET --s3-iam-endpoint $AWS_ENDPOINT_URL \
--s3-iam-noverify"
export IAM_PARAMS
return 0
fi
fail "unrecognized IAM_TYPE value: $IAM_TYPE"
log 1 "unrecognized IAM_TYPE value: $IAM_TYPE"
exit 1
}
27 changes: 20 additions & 7 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ show_help() {
echo "Usage: $0 [option...]"
echo " -h, --help Display this help message and exit"
echo " -s, --static Don't remove buckets between tests"
echo " aws Run tests with aws (s3api) cli"
echo " s3api Run tests with s3api cli"
echo " s3api-non-policy Run policy tests with s3api cli"
echo " s3api-policy Run policy tests with s3api cli"
echo " s3 Run tests with s3 cli"
echo " s3cmd Run tests with s3cmd utility"
echo " mc Run tests with mc utility"
echo " rest Run tests with rest cli"
echo " aws-user Run user tests with aws cli"
echo " s3api-user Run user tests with aws cli"
}

handle_param() {
Expand All @@ -34,7 +35,7 @@ handle_param() {
show_help
exit 0
;;
s3|s3api|aws|s3cmd|mc|aws-user|rest)
s3|s3api|s3cmd|mc|s3api-user|rest|s3api-policy|s3api-non-policy)
set_command_type "$1"
;;
*) # Handle unrecognized options or positional arguments
Expand Down Expand Up @@ -63,14 +64,26 @@ if [[ -z "$VERSITYGW_TEST_ENV" ]] && [[ $BYPASS_ENV_FILE != "true" ]]; then
exit 1
fi

exit_code=0
case $command_type in
s3api|aws)
echo "Running aws tests ..."
s3api)
echo "Running all s3api tests ..."
"$HOME"/bin/bats ./tests/test_s3api.sh || exit_code=$?
if [[ $exit_code -eq 0 ]]; then
"$HOME"/bin/bats ./tests/test_s3api_policy.sh || exit_code=$?
fi
if [[ $exit_code -eq 0 ]]; then
"$HOME"/bin/bats ./tests/test_user_aws.sh || exit_code=$?
fi
;;
s3api-policy)
echo "Running s3api policy tests ..."
"$HOME"/bin/bats ./tests/test_s3api_policy.sh || exit_code=$?
;;
s3api-non-policy)
echo "Running s3api non-policy tests ..."
"$HOME"/bin/bats ./tests/test_s3api.sh || exit_code=$?
;;
s3)
echo "Running s3 tests ..."
"$HOME"/bin/bats ./tests/test_s3.sh || exit_code=$?
Expand All @@ -90,8 +103,8 @@ case $command_type in
echo "Running rest tests ..."
"$HOME"/bin/bats ./tests/test_rest.sh || exit_code=$?
;;
aws-user)
echo "Running aws user tests ..."
s3api-user)
echo "Running s3api user tests ..."
"$HOME"/bin/bats ./tests/test_user_aws.sh || exit_code=$?
esac

Expand Down
Loading

0 comments on commit ae1c566

Please sign in to comment.