test: Update 3 files
All checks were successful
Build-Test-Publish / build (linux/arm64) (push) Successful in 32s
Build-Test-Publish / build (linux/amd64) (push) Successful in 32s

This commit is contained in:
Your Name
2025-09-02 20:41:02 +12:00
parent 944cc63502
commit f3cc793b5a
3 changed files with 125 additions and 6 deletions

118
test.sh
View File

@@ -313,7 +313,7 @@ test_metadata_multiple() {
local output=$(run_sos_upload "${TEST_DIR}/test_files/meta_multiple.txt" "meta:multiple" \
--metadata "field1=value1" \
--metadata "field2=value2" \
--metadata "templateXXHash64=abc123def456" 2>&1)
--metadata "unpackedhash=abc123def456" 2>&1)
# Check if upload succeeded
if ! echo "$output" | grep -q "Download URL:"; then
@@ -329,14 +329,14 @@ test_metadata_multiple() {
local field1=$(echo "$metadata" | jq -r '.metadata.field1')
local field2=$(echo "$metadata" | jq -r '.metadata.field2')
local xxhash=$(echo "$metadata" | jq -r '.metadata.templateXXHash64')
local xxhash=$(echo "$metadata" | jq -r '.metadata.unpackedhash')
if [[ "$field1" == "value1" && "$field2" == "value2" && "$xxhash" == "abc123def456" ]]; then
log_info "Multiple metadata fields working"
return 0
else
log_error "Metadata fields incorrect"
echo "field1=$field1, field2=$field2, templateXXHash64=$xxhash"
echo "field1=$field1, field2=$field2, unpackedhash=$xxhash"
return 1
fi
}
@@ -519,6 +519,116 @@ test_metadata_no_labels() {
fi
}
test_metadata_realistic_usage() {
log_info "Testing realistic usage with variables (like templates.dropshell.app example)..."
# Simulate real-world usage with variables
local SERVER="templates.dropshell.app" # Will actually use test server
local TARBALL="${TEST_DIR}/test_files/template.tar.gz"
local TEMPLATE="caddy"
local XXHASH="d4a7f3b2e1c9f8a5"
# Create a test tarball
echo "test template content" > "${TEST_DIR}/test_files/template_content.txt"
tar -czf "$TARBALL" -C "${TEST_DIR}/test_files" template_content.txt 2>/dev/null
# Test the exact pattern from the user's example
export SOS_WRITE_TOKEN="${TEST_TOKEN}"
export SOS_TEST_MODE=1
local host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
# Run the command with the same structure as the user's example
set +e
local output=$("${SCRIPT_DIR}/sos" upload "$host" "$TARBALL" "${TEMPLATE}:latest" --metadata "unpackedhash=$XXHASH" 2>&1)
local exit_code=$?
set -e
if [[ $exit_code -eq 0 ]] && echo "$output" | grep -q "Download URL:"; then
# Verify the upload worked correctly
local hash=$(curl -s "http://${host}/hash/${TEMPLATE}:latest" | jq -r '.hash')
local metadata=$(curl -s "http://${host}/meta/${hash}")
local xxhash_value=$(echo "$metadata" | jq -r '.metadata.unpackedhash')
local has_label=$(echo "$metadata" | jq -r '.metadata.labeltags | map(select(. == "caddy:latest")) | length')
if [[ "$xxhash_value" == "$XXHASH" && "$has_label" == "1" ]]; then
log_info "Realistic usage pattern working correctly"
return 0
else
log_error "Realistic usage pattern metadata incorrect"
echo "Expected unpackedhash=$XXHASH, got=$xxhash_value"
echo "Expected label caddy:latest, has_label=$has_label"
return 1
fi
else
log_error "Realistic usage pattern upload failed"
echo "Exit code: $exit_code"
echo "$output" | head -5
return 1
fi
}
test_metadata_realistic_multi() {
log_info "Testing realistic usage with multiple metadata fields..."
# More complex real-world scenario with multiple metadata fields
local TARBALL="${TEST_DIR}/test_files/app.tar.gz"
local APP_NAME="nginx"
local VERSION="1.25.3"
local BUILD_ID="build-$(date +%s)"
local COMMIT_SHA="abc123def456"
local AUTHOR="deploy-bot"
# Create test tarball
echo "app content v${VERSION}" > "${TEST_DIR}/test_files/app_content.txt"
tar -czf "$TARBALL" -C "${TEST_DIR}/test_files" app_content.txt 2>/dev/null
# Test with multiple metadata fields in realistic order
local output=$(run_sos_upload "$TARBALL" \
"${APP_NAME}:${VERSION}" \
"${APP_NAME}:latest" \
--metadata "version=$VERSION" \
--metadata "buildId=$BUILD_ID" \
--metadata "commitSha=$COMMIT_SHA" \
--metadata "deployedBy=$AUTHOR" \
--metadata "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" 2>&1)
if echo "$output" | grep -q "Download URL:"; then
# Verify all metadata was stored correctly
local host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
local hash=$(curl -s "http://${host}/hash/${APP_NAME}:${VERSION}" | jq -r '.hash')
local metadata=$(curl -s "http://${host}/meta/${hash}")
local stored_version=$(echo "$metadata" | jq -r '.metadata.version')
local stored_build=$(echo "$metadata" | jq -r '.metadata.buildId')
local stored_commit=$(echo "$metadata" | jq -r '.metadata.commitSha')
local stored_author=$(echo "$metadata" | jq -r '.metadata.deployedBy')
local has_version_label=$(echo "$metadata" | jq -r ".metadata.labeltags | map(select(. == \"${APP_NAME}:${VERSION}\")) | length")
local has_latest_label=$(echo "$metadata" | jq -r ".metadata.labeltags | map(select(. == \"${APP_NAME}:latest\")) | length")
if [[ "$stored_version" == "$VERSION" && \
"$stored_build" == "$BUILD_ID" && \
"$stored_commit" == "$COMMIT_SHA" && \
"$stored_author" == "$AUTHOR" && \
"$has_version_label" == "1" && \
"$has_latest_label" == "1" ]]; then
log_info "Realistic multi-metadata usage working correctly"
return 0
else
log_error "Realistic multi-metadata usage incorrect"
echo "version: expected=$VERSION, got=$stored_version"
echo "buildId: expected=$BUILD_ID, got=$stored_build"
echo "commitSha: expected=$COMMIT_SHA, got=$stored_commit"
echo "deployedBy: expected=$AUTHOR, got=$stored_author"
return 1
fi
else
log_error "Realistic multi-metadata upload failed"
echo "$output" | head -5
return 1
fi
}
test_metadata_ordering_comprehensive() {
log_info "Testing comprehensive metadata and label ordering combinations..."
@@ -730,6 +840,8 @@ run_tests() {
"test_metadata_empty_value"
"test_metadata_invalid_format"
"test_metadata_no_labels"
"test_metadata_realistic_usage"
"test_metadata_realistic_multi"
"test_metadata_ordering_comprehensive"
)