Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fqjony committed Feb 12, 2025
1 parent ef91d9a commit f51fbb2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
3 changes: 1 addition & 2 deletions lib/auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ authenticate_actors() {
if [[ -z "$creds" ]]; then
continue
else
log_info "Detected credentials for $type"
log_success "Authentication" "Detected credentials for $type"
fi

# Explicitly check for JSON format
Expand Down Expand Up @@ -121,7 +121,6 @@ authenticate_provider() {

# Set an environment variable to mark successful authorization
export "${provider^^}_AUTHORIZED=true"
log_info "Authorization successful for provider $provider."

return 0
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cleanup_provider() {
return 1
fi
else
log_info "$name authentication cleaned up successfully."
log_success "Cleanup" "$name authentication cleaned up successfully."
cleaned_up=true
fi

Expand Down
2 changes: 1 addition & 1 deletion lib/secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fetch_secrets() {
# Export the secret as an environment variable
if [[ -n "$value" ]]; then
echo "export $name=\"$value\"" >> "$secrets_env_file"
log_success "Resolved secret for $name from $provider."
log_success "Secrets" "Resolved secret for $name from $provider."
else
log_error "Secrets" "Failed to resolve secret for $name from $provider."
fi
Expand Down
11 changes: 9 additions & 2 deletions lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ resolve_env_vars() {
}

# Logging functions with direct ANSI sequences
# log_info() {
# if [ $# -eq 1 ]; then
# printf "\033[0;34m[INFO] %s\033[0m\n" "$1" >&2
# else
# printf "\033[0;34m[INFO] %s: %s\033[0m\n" "$1" "$2" >&2
# fi
# }
log_info() {
if [ $# -eq 1 ]; then
printf "\033[0;34m[INFO] %s\033[0m\n" "$1" >&2
printf "[INFO] %s\n" "$1" >&2
else
printf "\033[0;34m[INFO] %s: %s\033[0m\n" "$1" "$2" >&2
printf "[INFO] %s: %s\n" "$1" "$2" >&2
fi
}

Expand Down
4 changes: 2 additions & 2 deletions lib/worker_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ merge_worker_configs() {

# If a user-provided configuration exists (and path is not empty), merge it
if [[ -f "$USER_CONFIG" && -n "$USER_CONFIG" ]]; then
log_info "User configuration detected at $USER_CONFIG"
log_success "Worker configuration" "User configuration detected at $USER_CONFIG"

if ! yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' "$BUILT_IN_CONFIG" "$USER_CONFIG" > "$MERGED_CONFIG"; then
log_error "Worker configuration" "Failed to merge configurations. yq returned an error."
Expand Down Expand Up @@ -79,7 +79,7 @@ export_variables_from_config() {
log_info "No variables found in the configuration."
return 0
else
log_info "Found variables in the configuration. Exporting..."
log_success "Worker configuration" "Found variables in the configuration. Exporting..."
fi

# Iterate over variables and export them into the main shell
Expand Down
2 changes: 1 addition & 1 deletion src/tests/tasks/10_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check_command() {
local cmd_path
cmd_path=$(command -v "$1")
if [ -x "$cmd_path" ]; then
log_info "$1 is installed at $cmd_path"
log_success "$1" "$1 is installed at $cmd_path"
local version
version=$($1 --version 2>&1 | head -n 1)
log_success "$1" "Version: $version"
Expand Down
20 changes: 10 additions & 10 deletions src/tests/tasks/40_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_services() {

# Test 1: Check service configuration
log_info "Testing service configuration..."
if ! worker service config | grep -q "test_service"; then
if ! worker service config 2>/dev/null | grep -q "test_service"; then
log_error "$test_name" "test_service not found in configuration"
return 1
fi
Expand All @@ -21,27 +21,27 @@ test_services() {
log_info "Testing service lifecycle..."

# Start service
worker service start test_service
worker service start test_service > /dev/null
sleep 2
if ! worker service status test_service | grep -q "RUNNING"; then
if ! worker service status test_service 2>/dev/null | grep -q "RUNNING"; then
log_error "$test_name" "Failed to start service"
return 1
fi
log_success "$test_name" "Service started successfully"

# Stop service
worker service stop test_service
worker service stop test_service > /dev/null
sleep 5 # Allow time for graceful shutdown
if worker service status test_service | grep -q "RUNNING"; then
if worker service status test_service 2>/dev/null | grep -q "RUNNING"; then
log_error "$test_name" "Failed to stop service"
return 1
fi
log_success "$test_name" "Service stopped successfully"

# Restart service
worker service restart test_service
worker service restart test_service > /dev/null
sleep 2
if ! worker service status test_service | grep -q "RUNNING"; then
if ! worker service status test_service 2>/dev/null | grep -q "RUNNING"; then
log_error "$test_name" "Failed to restart service"
return 1
fi
Expand All @@ -57,16 +57,16 @@ test_services() {

# Test 4: Graceful shutdown
log_info "Testing graceful shutdown..."
worker service stop test_service
worker service stop test_service > /dev/null
sleep 1

# Check logs for cleanup
if ! worker service logs test_service | grep -q "Starting cleanup..."; then
if ! worker service logs test_service 2>/dev/null | grep -q "Starting cleanup..."; then
log_error "$test_name" "Service did not initiate cleanup"
return 1
fi
sleep 5
if ! worker service logs test_service | grep -q "Cleanup completed"; then
if ! worker service logs test_service 2>/dev/null | grep -q "Cleanup completed"; then
log_error "$test_name" "Service did not complete cleanup"
return 1
fi
Expand Down
12 changes: 6 additions & 6 deletions src/tests/tasks/50_graceful_shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ test_graceful_shutdown() {
log_info "$test_name: Test graceful shutdown of services"

# Start the long-running service defined in services.yaml
worker service start test_service
worker service start test_service > /dev/null
sleep 5

# Check if service is running
if ! worker service status test_service | grep -q "RUNNING"; then
if ! worker service status test_service 2>/dev/null | grep -q "RUNNING"; then
log_error "$test_name" "Service failed to start"
return 1
fi
log_success "$test_name" "Service started successfully"

# Stop the service
worker service stop test_service
worker service stop test_service > /dev/null

# Wait for graceful shutdown (should take about 5 seconds based on our test service)
sleep 7

# Check if service has stopped
if worker service status test_service | grep -q "RUNNING"; then
if worker service status test_service 2>/dev/null | grep -q "RUNNING"; then
log_error "$test_name" "Service did not exit gracefully within timeout"
return 1
fi
log_success "$test_name" "Service exited gracefully"

# Check service logs for proper shutdown sequence
if ! worker service logs test_service | grep -q "Starting cleanup..."; then
if ! worker service logs test_service 2>/dev/null | grep -q "Starting cleanup..."; then
log_error "$test_name" "Service did not initiate cleanup"
return 1
fi
log_success "$test_name" "Service cleanup initiated"

if ! worker service logs test_service | grep -q "Cleanup completed"; then
if ! worker service logs test_service 2>/dev/null | grep -q "Cleanup completed"; then
log_error "$test_name" "Service did not complete cleanup"
return 1
fi
Expand Down

0 comments on commit f51fbb2

Please sign in to comment.