test: Update 3 files
This commit is contained in:
11
publish.sh
11
publish.sh
@@ -1,9 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
PROJECT="$(basename "${SCRIPT_DIR}")"
|
PROJECT="$(basename "${SCRIPT_DIR}")"
|
||||||
OUTPUT="${SCRIPT_DIR}/output"
|
OUTPUT="${SCRIPT_DIR}/output"
|
||||||
|
VERSION=$(date -u +"%Y.%m%d.%H%M")
|
||||||
|
|
||||||
|
|
||||||
function heading() {
|
function heading() {
|
||||||
@@ -45,7 +48,11 @@ heading "Publishing ${PROJECT} as tool to ${PROJECT}:${ARCH} (on getpkg.xyz)"
|
|||||||
|
|
||||||
TOOLDIR="${OUTPUT}/tool"
|
TOOLDIR="${OUTPUT}/tool"
|
||||||
mkdir "${TOOLDIR}"
|
mkdir "${TOOLDIR}"
|
||||||
cp "${PROJECT}" "${TOOLDIR}/${PROJECT}"
|
|
||||||
|
# Copy the script and replace __VERSION__ with the actual version
|
||||||
|
sed "s|__VERSION__|${VERSION}|g" "${PROJECT}" > "${TOOLDIR}/${PROJECT}"
|
||||||
|
chmod +x "${TOOLDIR}/${PROJECT}"
|
||||||
|
|
||||||
"${GETPKG_PATH}" server set-token getpkg.xyz "${SOS_WRITE_TOKEN}"
|
"${GETPKG_PATH}" server set-token getpkg.xyz "${SOS_WRITE_TOKEN}"
|
||||||
"${GETPKG_PATH}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
|
"${GETPKG_PATH}" publish "${PROJECT}:${ARCH}" "${TOOLDIR}"
|
||||||
|
|
||||||
@@ -62,7 +69,7 @@ fi
|
|||||||
|
|
||||||
# Upload architecture-specific binary to getbin.xyz
|
# Upload architecture-specific binary to getbin.xyz
|
||||||
heading "Uploading ${PROJECT} binary to getbin.xyz as ${PROJECT}:latest-${ARCH}"
|
heading "Uploading ${PROJECT} binary to getbin.xyz as ${PROJECT}:latest-${ARCH}"
|
||||||
"${SOS}" upload "getbin.xyz" "${PROJECT}" "${PROJECT}:latest-${ARCH}" || die "Failed to upload ${PROJECT} binary to getbin.xyz"
|
"${SOS}" upload "getbin.xyz" "${TOOLDIR}/${PROJECT}" "${PROJECT}:latest-${ARCH}" || die "Failed to upload ${PROJECT} binary to getbin.xyz"
|
||||||
|
|
||||||
# Check if there's an install script to upload
|
# Check if there's an install script to upload
|
||||||
if [ -f "${SCRIPT_DIR}/install.sh" ]; then
|
if [ -f "${SCRIPT_DIR}/install.sh" ]; then
|
||||||
|
2
sos
2
sos
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
VERSION="2025.0817.0949"
|
VERSION="__VERSION__"
|
||||||
|
|
||||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
TEMP_DIR=$(mktemp -d)
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
118
test.sh
118
test.sh
@@ -313,7 +313,7 @@ test_metadata_multiple() {
|
|||||||
local output=$(run_sos_upload "${TEST_DIR}/test_files/meta_multiple.txt" "meta:multiple" \
|
local output=$(run_sos_upload "${TEST_DIR}/test_files/meta_multiple.txt" "meta:multiple" \
|
||||||
--metadata "field1=value1" \
|
--metadata "field1=value1" \
|
||||||
--metadata "field2=value2" \
|
--metadata "field2=value2" \
|
||||||
--metadata "templateXXHash64=abc123def456" 2>&1)
|
--metadata "unpackedhash=abc123def456" 2>&1)
|
||||||
|
|
||||||
# Check if upload succeeded
|
# Check if upload succeeded
|
||||||
if ! echo "$output" | grep -q "Download URL:"; then
|
if ! echo "$output" | grep -q "Download URL:"; then
|
||||||
@@ -329,14 +329,14 @@ test_metadata_multiple() {
|
|||||||
|
|
||||||
local field1=$(echo "$metadata" | jq -r '.metadata.field1')
|
local field1=$(echo "$metadata" | jq -r '.metadata.field1')
|
||||||
local field2=$(echo "$metadata" | jq -r '.metadata.field2')
|
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
|
if [[ "$field1" == "value1" && "$field2" == "value2" && "$xxhash" == "abc123def456" ]]; then
|
||||||
log_info "Multiple metadata fields working"
|
log_info "Multiple metadata fields working"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
log_error "Metadata fields incorrect"
|
log_error "Metadata fields incorrect"
|
||||||
echo "field1=$field1, field2=$field2, templateXXHash64=$xxhash"
|
echo "field1=$field1, field2=$field2, unpackedhash=$xxhash"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -519,6 +519,116 @@ test_metadata_no_labels() {
|
|||||||
fi
|
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() {
|
test_metadata_ordering_comprehensive() {
|
||||||
log_info "Testing comprehensive metadata and label ordering combinations..."
|
log_info "Testing comprehensive metadata and label ordering combinations..."
|
||||||
|
|
||||||
@@ -730,6 +840,8 @@ run_tests() {
|
|||||||
"test_metadata_empty_value"
|
"test_metadata_empty_value"
|
||||||
"test_metadata_invalid_format"
|
"test_metadata_invalid_format"
|
||||||
"test_metadata_no_labels"
|
"test_metadata_no_labels"
|
||||||
|
"test_metadata_realistic_usage"
|
||||||
|
"test_metadata_realistic_multi"
|
||||||
"test_metadata_ordering_comprehensive"
|
"test_metadata_ordering_comprehensive"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user