release: hmac-file-server 3.2
This commit is contained in:
173
test/test_installer_config.sh
Executable file
173
test/test_installer_config.sh
Executable file
@ -0,0 +1,173 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test script to validate installer configuration generation
|
||||
# Tests that the installer generates config compatible with fixed struct definitions
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}🔍 Testing Installer Configuration Generation${NC}"
|
||||
echo "============================================="
|
||||
echo ""
|
||||
|
||||
# Test configuration values that simulate installer input
|
||||
export HMAC_SECRET="test-hmac-secret-32-characters-long-minimum"
|
||||
export JWT_SECRET="test-jwt-secret-also-32-characters-long-minimum"
|
||||
|
||||
# Create a test directory
|
||||
TEST_DIR="/tmp/hmac-installer-test-$$"
|
||||
mkdir -p "$TEST_DIR"
|
||||
cd "$TEST_DIR"
|
||||
|
||||
echo -e "${YELLOW}📁 Test directory: $TEST_DIR${NC}"
|
||||
echo ""
|
||||
|
||||
# Copy necessary files for testing
|
||||
cp /home/renz/source/hmac-file-server-uuxo/go.mod .
|
||||
cp /home/renz/source/hmac-file-server-uuxo/go.sum .
|
||||
cp -r /home/renz/source/hmac-file-server-uuxo/cmd .
|
||||
|
||||
# Extract the generate_config function and create a test version
|
||||
cat > test_config_generation.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# Simulated installer variables
|
||||
DEFAULT_CONFIG_DIR="./test-config"
|
||||
DATA_DIR="./test-data"
|
||||
DEFAULT_LOG_DIR="./test-logs"
|
||||
SERVER_PORT="8080"
|
||||
METRICS_PORT="9090"
|
||||
ENABLE_TLS="false"
|
||||
HMAC_SECRET="test-hmac-secret-32-characters-long-minimum"
|
||||
ENABLE_JWT="false"
|
||||
ENABLE_CLAMAV="false"
|
||||
ENABLE_REDIS="false"
|
||||
|
||||
# Create directories
|
||||
mkdir -p "$DEFAULT_CONFIG_DIR"
|
||||
mkdir -p "$DATA_DIR/runtime"
|
||||
mkdir -p "$DEFAULT_LOG_DIR"
|
||||
|
||||
# Generate configuration (extracted from installer)
|
||||
generate_config() {
|
||||
echo "Generating test configuration..."
|
||||
|
||||
cat > "$DEFAULT_CONFIG_DIR/config.toml" << EOFCONFIG
|
||||
# HMAC File Server Configuration
|
||||
# Generated by installer test on $(date)
|
||||
|
||||
[server]
|
||||
bind_ip = "0.0.0.0"
|
||||
listenport = "$SERVER_PORT"
|
||||
unixsocket = false
|
||||
storagepath = "$DATA_DIR/uploads"
|
||||
metricsenabled = true
|
||||
metricsport = "$METRICS_PORT"
|
||||
deduplicationenabled = true
|
||||
deduplicationpath = "$DATA_DIR/deduplication"
|
||||
filenaming = "HMAC"
|
||||
force_protocol = "auto"
|
||||
pidfilepath = "$DATA_DIR/runtime/hmac-file-server.pid"
|
||||
sslenabled = false
|
||||
|
||||
[security]
|
||||
secret = "$HMAC_SECRET"
|
||||
enablejwt = false
|
||||
|
||||
[uploads]
|
||||
allowedextensions = [".txt", ".pdf", ".jpg", ".jpeg", ".png", ".gif", ".webp", ".zip", ".tar", ".gz", ".7z", ".mp4", ".webm", ".ogg", ".mp3", ".wav", ".flac", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".ods", ".odp"]
|
||||
maxfilesize = "100MB"
|
||||
chunkeduploadsenabled = true
|
||||
chunksize = "10MB"
|
||||
ttlenabled = false
|
||||
ttl = "168h"
|
||||
|
||||
[downloads]
|
||||
chunkeddownloadsenabled = true
|
||||
chunksize = "10MB"
|
||||
|
||||
[logging]
|
||||
level = "INFO"
|
||||
file = "$DEFAULT_LOG_DIR/hmac-file-server.log"
|
||||
max_size = 100
|
||||
max_backups = 3
|
||||
max_age = 30
|
||||
compress = true
|
||||
|
||||
[workers]
|
||||
numworkers = 10
|
||||
uploadqueuesize = 1000
|
||||
autoscaling = true
|
||||
|
||||
[timeouts]
|
||||
readtimeout = "30s"
|
||||
writetimeout = "30s"
|
||||
idletimeout = "120s"
|
||||
shutdown = "30s"
|
||||
|
||||
[clamav]
|
||||
enabled = false
|
||||
|
||||
[redis]
|
||||
enabled = false
|
||||
EOFCONFIG
|
||||
|
||||
echo "Configuration file created: $DEFAULT_CONFIG_DIR/config.toml"
|
||||
}
|
||||
|
||||
# Call the function
|
||||
generate_config
|
||||
EOF
|
||||
|
||||
chmod +x test_config_generation.sh
|
||||
./test_config_generation.sh
|
||||
|
||||
echo -e "${YELLOW}📋 Generated test configuration:${NC}"
|
||||
echo ""
|
||||
cat ./test-config/config.toml
|
||||
echo ""
|
||||
|
||||
# Build a test binary to validate the configuration
|
||||
echo -e "${YELLOW}🔨 Building test binary...${NC}"
|
||||
if go build -o hmac-test-server ./cmd/server/*.go; then
|
||||
echo -e "${GREEN}✅ Build successful${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Build failed${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}🔍 Testing configuration validation...${NC}"
|
||||
|
||||
# Test configuration validation
|
||||
if ./hmac-test-server -config ./test-config/config.toml -validate-config -validate-quiet; then
|
||||
echo -e "${GREEN}✅ Configuration validation PASSED!${NC}"
|
||||
echo ""
|
||||
echo -e "${GREEN}🎉 All critical fixes verified:${NC}"
|
||||
echo -e "${GREEN} ✓ Workers: numworkers/uploadqueuesize (not initial/max)${NC}"
|
||||
echo -e "${GREEN} ✓ Protocol: force_protocol (not forceprotocol)${NC}"
|
||||
echo -e "${GREEN} ✓ PID file: pidfilepath configured${NC}"
|
||||
echo -e "${GREEN} ✓ Timeouts: read/write/idle/shutdown${NC}"
|
||||
echo -e "${GREEN} ✓ Logging: level/file/max_size/max_backups/max_age${NC}"
|
||||
VALIDATION_RESULT=0
|
||||
else
|
||||
echo -e "${RED}❌ Configuration validation FAILED!${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Running detailed validation for diagnosis...${NC}"
|
||||
./hmac-test-server -config ./test-config/config.toml -validate-config -validate-verbose || true
|
||||
VALIDATION_RESULT=1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}🧹 Cleaning up test directory...${NC}"
|
||||
cd /
|
||||
rm -rf "$TEST_DIR"
|
||||
|
||||
echo -e "${BLUE}Test completed.${NC}"
|
||||
exit $VALIDATION_RESULT
|
Reference in New Issue
Block a user