Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 98 additions & 12 deletions k8s/deployment/tests/apply_templates.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📝 Applying templates..."
assert_contains "$output" "📋 Directory:"
assert_contains "$output" "📋 Action: apply"
assert_contains "$output" "📋 Dry run: false"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: false

📝 kubectl apply valid.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -65,7 +73,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📋 Skipping empty template: empty.yaml"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: false

📋 Skipping empty template: empty.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -79,7 +98,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📋 Skipping empty template: whitespace.yaml"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: false

📋 Skipping empty template: whitespace.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -92,7 +122,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📋 Skipping empty template: newlines.yaml"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: false

📋 Skipping empty template: newlines.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -104,7 +145,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📝 kubectl apply valid.yaml"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: false

📝 kubectl apply valid.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -129,7 +181,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📋 Skipping empty template: empty.yaml"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: false

📋 Skipping empty template: empty.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -142,7 +205,18 @@ teardown() {
run bash "$SERVICE_PATH/apply_templates"

[ "$status" -eq 0 ]
assert_contains "$output" "📋 Skipping empty template"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: delete
📋 Dry run: false

📋 Skipping empty template: empty.yaml
📋 Manifest backup is disabled, skipping
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -157,6 +231,18 @@ teardown() {

# Dry run exits with 1
[ "$status" -eq 1 ]
assert_contains "$output" "📋 Skipping empty template: empty.yaml"
assert_contains "$output" "📋 Dry run mode - no changes were made"
local expected
expected=$(cat <<EOF
📝 Applying templates...
📋 Directory: $OUTPUT_DIR
📋 Action: apply
📋 Dry run: true

📋 Skipping empty template: empty.yaml
📝 kubectl apply valid.yaml

📋 Dry run mode - no changes were made
EOF
)
assert_equal "$output" "$expected"
}
62 changes: 37 additions & 25 deletions k8s/deployment/tests/build_context.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ teardown() {
@test "validate_status: accepts valid statuses for start-initial and start-blue-green" {
run validate_status "start-initial" "creating"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action 'start-initial' (current status: 'creating', expected: creating, waiting_for_instances or running)"
assert_equal "$output" "📝 Running action 'start-initial' (current status: 'creating', expected: creating, waiting_for_instances or running)"

run validate_status "start-initial" "waiting_for_instances"
[ "$status" -eq 0 ]
Expand All @@ -43,7 +43,7 @@ teardown() {

run validate_status "start-blue-green" "creating"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action 'start-blue-green' (current status: 'creating', expected: creating, waiting_for_instances or running)"
assert_equal "$output" "📝 Running action 'start-blue-green' (current status: 'creating', expected: creating, waiting_for_instances or running)"
}

@test "validate_status: rejects invalid statuses for start-initial" {
Expand All @@ -57,7 +57,7 @@ teardown() {
@test "validate_status: accepts valid statuses for switch-traffic" {
run validate_status "switch-traffic" "running"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action 'switch-traffic' (current status: 'running', expected: running or waiting_for_instances)"
assert_equal "$output" "📝 Running action 'switch-traffic' (current status: 'running', expected: running or waiting_for_instances)"

run validate_status "switch-traffic" "waiting_for_instances"
[ "$status" -eq 0 ]
Expand All @@ -71,7 +71,7 @@ teardown() {
@test "validate_status: accepts valid statuses for rollback-deployment" {
run validate_status "rollback-deployment" "rolling_back"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action 'rollback-deployment' (current status: 'rolling_back', expected: rolling_back or cancelling)"
assert_equal "$output" "📝 Running action 'rollback-deployment' (current status: 'rolling_back', expected: rolling_back or cancelling)"

run validate_status "rollback-deployment" "cancelling"
[ "$status" -eq 0 ]
Expand All @@ -98,7 +98,7 @@ teardown() {
@test "validate_status: accepts valid statuses for delete-deployment" {
run validate_status "delete-deployment" "deleting"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action 'delete-deployment' (current status: 'deleting', expected: deleting, rolling_back or cancelling)"
assert_equal "$output" "📝 Running action 'delete-deployment' (current status: 'deleting', expected: deleting, rolling_back or cancelling)"

run validate_status "delete-deployment" "cancelling"
[ "$status" -eq 0 ]
Expand All @@ -115,11 +115,11 @@ teardown() {
@test "validate_status: accepts any status for unknown or empty action" {
run validate_status "custom-action" "any_status"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action 'custom-action', any deployment status is accepted"
assert_equal "$output" "📝 Running action 'custom-action', any deployment status is accepted"

run validate_status "" "running"
[ "$status" -eq 0 ]
assert_contains "$output" "📝 Running action '', any deployment status is accepted"
assert_equal "$output" "📝 Running action '', any deployment status is accepted"
}

# =============================================================================
Expand Down Expand Up @@ -560,15 +560,21 @@ SCRIPT
run "$test_script" "$mock_service"

[ "$status" -ne 0 ]
assert_contains "$output" "❌ Invalid deployment status 'failed' for action 'start-initial'"
assert_contains "$output" "💡 Possible causes:"
assert_contains "$output" "Deployment status changed during workflow execution"
assert_contains "$output" "Another action is already running on this deployment"
assert_contains "$output" "Deployment was modified externally"
assert_contains "$output" "🔧 How to fix:"
assert_contains "$output" "Wait for any in-progress actions to complete"
assert_contains "$output" "Check the deployment status in the nullplatform dashboard"
assert_contains "$output" "Retry the action once the deployment is in the expected state"
local expected
expected=$(cat <<'EOF'
📝 Running action 'start-initial' (current status: 'failed', expected: creating, waiting_for_instances or running)
❌ Invalid deployment status 'failed' for action 'start-initial'
💡 Possible causes:
- Deployment status changed during workflow execution
- Another action is already running on this deployment
- Deployment was modified externally
🔧 How to fix:
- Wait for any in-progress actions to complete
- Check the deployment status in the nullplatform dashboard
- Retry the action once the deployment is in the expected state
EOF
)
assert_equal "$output" "$expected"
}

@test "error: ConfigMap not found shows full troubleshooting info" {
Expand Down Expand Up @@ -608,15 +614,21 @@ SCRIPT
run "$test_script" "$mock_service"

[ "$status" -ne 0 ]
assert_contains "$output" "🔍 Validating ConfigMap 'test-config' in namespace 'test-ns'"
assert_contains "$output" "❌ ConfigMap 'test-config' does not exist in namespace 'test-ns'"
assert_contains "$output" "💡 Possible causes:"
assert_contains "$output" "ConfigMap was not created before deployment"
assert_contains "$output" "ConfigMap name is misspelled in values.yaml"
assert_contains "$output" "ConfigMap was deleted or exists in a different namespace"
assert_contains "$output" "🔧 How to fix:"
assert_contains "$output" "Create the ConfigMap: kubectl create configmap test-config -n test-ns --from-file=nginx.conf --from-file=default.conf"
assert_contains "$output" "Verify the ConfigMap name in your scope configuration"
local expected
expected=$(cat <<'EOF'
📝 Running action 'start-initial' (current status: 'creating', expected: creating, waiting_for_instances or running)
🔍 Validating ConfigMap 'test-config' in namespace 'test-ns'
❌ ConfigMap 'test-config' does not exist in namespace 'test-ns'
💡 Possible causes:
- ConfigMap was not created before deployment
- ConfigMap name is misspelled in values.yaml
- ConfigMap was deleted or exists in a different namespace
🔧 How to fix:
- Create the ConfigMap: kubectl create configmap test-config -n test-ns --from-file=nginx.conf --from-file=default.conf
- Verify the ConfigMap name in your scope configuration
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand Down
59 changes: 36 additions & 23 deletions k8s/deployment/tests/build_deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,23 @@ teardown() {

[ "$status" -eq 0 ]

# Header messages
assert_contains "$output" "📝 Building deployment templates..."
assert_contains "$output" "📋 Output directory:"

# Deployment template
assert_contains "$output" "✅ Deployment template:"

# Secret template
assert_contains "$output" "✅ Secret template:"

# Scaling template
assert_contains "$output" "✅ Scaling template:"

# Service template
assert_contains "$output" "✅ Service template:"

# PDB template
assert_contains "$output" "✅ PDB template:"

# Summary
assert_contains "$output" "✨ All templates built successfully"
local expected
expected=$(cat <<EOF
📝 Building deployment templates...
📋 Output directory: $OUTPUT_DIR

✅ Deployment template: $OUTPUT_DIR/deployment-scope-123-deploy-456.yaml
✅ Secret template: $OUTPUT_DIR/secret-scope-123-deploy-456.yaml
✅ Secret-files template: $OUTPUT_DIR/secret-files-scope-123-deploy-456.yaml
✅ Scaling template: $OUTPUT_DIR/scaling-scope-123-deploy-456.yaml
✅ Service template: $OUTPUT_DIR/service-scope-123-deploy-456.yaml
📝 Building PDB template...
✅ PDB template: $OUTPUT_DIR/pdb-scope-123-deploy-456.yaml

✨ All templates built successfully
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand All @@ -99,7 +95,15 @@ teardown() {
run bash "$BATS_TEST_DIRNAME/../build_deployment"

[ "$status" -eq 1 ]
assert_contains "$output" "❌ Failed to build deployment template"
local expected
expected=$(cat <<EOF
📝 Building deployment templates...
📋 Output directory: $OUTPUT_DIR

❌ Failed to build deployment template
EOF
)
assert_equal "$output" "$expected"
}

@test "build_deployment: fails when secret template generation fails" {
Expand All @@ -124,7 +128,16 @@ teardown() {
run bash "$BATS_TEST_DIRNAME/../build_deployment"

[ "$status" -eq 1 ]
assert_contains "$output" "❌ Failed to build secret template"
local expected
expected=$(cat <<EOF
📝 Building deployment templates...
📋 Output directory: $OUTPUT_DIR

✅ Deployment template: $OUTPUT_DIR/deployment-scope-123-deploy-456.yaml
❌ Failed to build secret template
EOF
)
assert_equal "$output" "$expected"
}

# =============================================================================
Expand Down
Loading
Loading