test: add a test case to test rclone config exists
This commit is contained in:
@@ -5,6 +5,7 @@ DOCKER_IMAGE="ttionya/vaultwarden-backup:test"
|
||||
ERROR_NUM=0
|
||||
|
||||
DATA_DIR="$(pwd)/tests/fixtures/source/bitwarden/data"
|
||||
CONFIG_DIR="config"
|
||||
OUTPUT_DIR="output"
|
||||
EXTRACT_DIR="extract"
|
||||
TEMP_DIR="tmp"
|
||||
@@ -88,6 +89,7 @@ function test_result() {
|
||||
}
|
||||
|
||||
. tests/units/env-priority/test.sh
|
||||
. tests/units/check-rclone-config-exists/test.sh
|
||||
. tests/units/check-rclone-connection-initializing/test.sh
|
||||
. tests/units/backup-zip-file/test.sh
|
||||
. tests/units/backup-7z-file/test.sh
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
# During Rclone connection verification, the configuration is considered complete
|
||||
# by checking for the presence of `RCLONE_REMOTE_NAME` in the configuration file.
|
||||
#
|
||||
# This test case ensures the verification method works by triggering the expected error message.
|
||||
|
||||
TEST_NAME="check-rclone-config-exits"
|
||||
TEST_OUTPUT_DIR="$(pwd)/${OUTPUT_DIR}/${TEST_NAME}"
|
||||
TEST_CONFIG_DIR="$(pwd)/${CONFIG_DIR}/${TEST_NAME}"
|
||||
|
||||
PASSWORD="231454f1-594c-45e2-8810-3ac917ebcf70"
|
||||
|
||||
FAILED_NUM=0
|
||||
|
||||
color yellow "Starting test case \"${TEST_NAME}\""
|
||||
|
||||
function prepare() {
|
||||
mkdir -p "${TEST_OUTPUT_DIR}" "${TEST_CONFIG_DIR}"
|
||||
}
|
||||
|
||||
function start() {
|
||||
echo ""
|
||||
}
|
||||
|
||||
function test() {
|
||||
color blue "Testing..."
|
||||
|
||||
FOUND_MESSAGE_COUNT=$(docker run --rm \
|
||||
--mount "type=bind,source=${TEST_OUTPUT_DIR},target=${REMOTE_DIR}" \
|
||||
--mount "type=bind,source=${TEST_RCLONE_CONFIG_DIR},target=/config" \
|
||||
-e "RCLONE_REMOTE_DIR=${REMOTE_DIR}" \
|
||||
-e "ZIP_PASSWORD=${PASSWORD}" \
|
||||
-e "BACKUP_FILE_SUFFIX=test" \
|
||||
"${DOCKER_IMAGE}" \
|
||||
backup | grep -c "rclone configuration information not found")
|
||||
|
||||
if [[ "${FOUND_MESSAGE_COUNT}" -ne 1 ]]; then
|
||||
((FAILED_NUM++))
|
||||
fi
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
sudo rm -rf "${TEST_OUTPUT_DIR}" "${TEST_CONFIG_DIR}"
|
||||
|
||||
unset TEST_OUTPUT_DIR
|
||||
unset TEST_CONFIG_DIR
|
||||
unset PASSWORD
|
||||
unset FOUND_MESSAGE_COUNT
|
||||
}
|
||||
|
||||
prepare
|
||||
start
|
||||
test
|
||||
cleanup
|
||||
|
||||
test_result "${TEST_NAME}" "${FAILED_NUM}"
|
||||
@@ -1,5 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# When verifying the Rclone connection, the previous method ensured
|
||||
# the remote directory existed by creating it (mkdir), which requires special permissions on S3.
|
||||
# It has been changed to attempt listing the remote directory (lsd) to avoid this issue.
|
||||
# If listing the directory fails, the directory is considered non-existent and will be created.
|
||||
# See issue https://github.com/ttionya/vaultwarden-backup/issues/199 for details.
|
||||
#
|
||||
# This test case verifies that the remote directory can be created correctly without affecting the backup operation.
|
||||
|
||||
TEST_NAME="check-rclone-connection-initializing"
|
||||
TEST_OUTPUT_DIR="$(pwd)/${OUTPUT_DIR}/${TEST_NAME}"
|
||||
TEST_EXTRACT_DIR="$(pwd)/${EXTRACT_DIR}/${TEST_NAME}"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# The tool can set environment variables in four ways.
|
||||
# This test case tests the priority by setting different passwords for the environment variable `ZIP_PASSWORD`.
|
||||
|
||||
TEST_NAME="env-priority"
|
||||
TEST_OUTPUT_DIR="$(pwd)/${OUTPUT_DIR}/${TEST_NAME}"
|
||||
TEST_TEMP_DIR="$(pwd)/${TEMP_DIR}/${TEST_NAME}"
|
||||
|
||||
Reference in New Issue
Block a user