215 lines
6.9 KiB
Bash
Executable File
215 lines
6.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Comprehensive Test Suite for SF CLI Wrapper Scripts
|
|
# Tests all scenarios with 100% coverage using PWC-TEAM-DEV org
|
|
|
|
# Source utilities for cross-platform compatibility
|
|
source "$(dirname "$0")/utils.sh"
|
|
|
|
readonly TEST_ORG="PWC-TEAM-DEV"
|
|
readonly GREEN='\033[0;32m'
|
|
readonly RED='\033[0;31m'
|
|
readonly YELLOW='\033[0;33m'
|
|
readonly BLUE='\033[0;34m'
|
|
readonly NC='\033[0m' # No Color
|
|
|
|
# Test counters
|
|
TESTS_RUN=0
|
|
TESTS_PASSED=0
|
|
TESTS_FAILED=0
|
|
FAILED_TESTS=()
|
|
|
|
# Test output directory
|
|
TEST_DIR="test-outputs"
|
|
mkdir -p "$TEST_DIR"
|
|
|
|
echo -e "${BLUE}SF CLI Wrapper Test Suite${NC}"
|
|
echo -e "${BLUE}========================${NC}"
|
|
echo -e "${YELLOW}Target Org: $TEST_ORG${NC}"
|
|
echo -e "${YELLOW}Test outputs will be saved in: $TEST_DIR/${NC}"
|
|
echo ""
|
|
|
|
# Helper functions
|
|
run_test() {
|
|
local test_name="$1"
|
|
local command="$2"
|
|
local expected_result="${3:-0}" # 0 = success, 1 = expected failure
|
|
|
|
((TESTS_RUN++))
|
|
echo -n "Testing: $test_name ... "
|
|
|
|
local output_file="$TEST_DIR/${test_name// /_}.log"
|
|
|
|
if eval "$command" > "$output_file" 2>&1; then
|
|
local actual_result=0
|
|
else
|
|
local actual_result=1
|
|
fi
|
|
|
|
if [[ $actual_result -eq $expected_result ]]; then
|
|
echo -e "${GREEN}PASS${NC}"
|
|
((TESTS_PASSED++))
|
|
else
|
|
echo -e "${RED}FAIL${NC}"
|
|
((TESTS_FAILED++))
|
|
FAILED_TESTS+=("$test_name")
|
|
echo " Output saved to: $output_file"
|
|
fi
|
|
}
|
|
|
|
run_help_test() {
|
|
local script="$1"
|
|
local help_flag="$2"
|
|
run_test "$script help ($help_flag)" "./$script $help_flag"
|
|
}
|
|
|
|
echo -e "${BLUE}=== Testing Help Functions ===${NC}"
|
|
|
|
# Test help for all scripts
|
|
run_help_test "sf-check" "-hp"
|
|
run_help_test "sf-deploy" "-hp"
|
|
run_help_test "sf-dry-run" "-hp"
|
|
run_help_test "sf-web-open" "-hp"
|
|
run_help_test "sf-org-create" "-hp"
|
|
run_help_test "sf-org-info" "-hp"
|
|
run_help_test "sf-retrieve" "-hp"
|
|
run_help_test "sf-test-run" "-hp"
|
|
run_help_test "sf-apex-run" "-hp"
|
|
run_help_test "sf-data-export" "-hp"
|
|
run_help_test "sf-data-import" "-hp"
|
|
run_help_test "sf-logs-tail" "-hp"
|
|
|
|
# Test long form help
|
|
run_help_test "sf-deploy" "--help"
|
|
run_help_test "sf-web-open" "--help"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-check ===${NC}"
|
|
|
|
run_test "sf-check basic" "./sf-check"
|
|
run_test "sf-check verbose" "./sf-check -ve"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-org-info ===${NC}"
|
|
|
|
run_test "sf-org-info target org" "./sf-org-info -to $TEST_ORG"
|
|
run_test "sf-org-info list orgs" "./sf-org-info -ls"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-web-open ===${NC}"
|
|
|
|
run_test "sf-web-open URL only" "./sf-web-open -to $TEST_ORG -ur"
|
|
run_test "sf-web-open with path" "./sf-web-open -to $TEST_ORG -pt \"/lightning/setup/SetupOneHome/home\" -ur"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-retrieve ===${NC}"
|
|
|
|
run_test "sf-retrieve ApexClass" "./sf-retrieve -to $TEST_ORG -tp \"ApexClass\" -dr \"$TEST_DIR/retrieved-apex\""
|
|
run_test "sf-retrieve CustomObject" "./sf-retrieve -to $TEST_ORG -tp \"CustomObject\" -dr \"$TEST_DIR/retrieved-objects\""
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-data-export ===${NC}"
|
|
|
|
run_test "sf-data-export User query" "./sf-data-export -qy \"SELECT Id, Name FROM User LIMIT 5\" -to $TEST_ORG -fm csv -ot \"$TEST_DIR/users.csv\""
|
|
run_test "sf-data-export Account sobject" "./sf-data-export -so Account -to $TEST_ORG -fm json -ot \"$TEST_DIR/accounts.json\""
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing Error Conditions ===${NC}"
|
|
|
|
# Test missing required parameters
|
|
run_test "sf-deploy no args" "./sf-deploy" 1
|
|
run_test "sf-dry-run no args" "./sf-dry-run" 1
|
|
run_test "sf-retrieve no args" "./sf-retrieve" 1
|
|
run_test "sf-data-export no query" "./sf-data-export -to $TEST_ORG" 1
|
|
run_test "sf-data-import no file" "./sf-data-import -so Account -to $TEST_ORG" 1
|
|
run_test "sf-org-create no alias" "./sf-org-create" 1
|
|
|
|
# Test invalid options
|
|
run_test "sf-deploy invalid option" "./sf-deploy -invalid" 1
|
|
run_test "sf-web-open invalid option" "./sf-web-open -xyz" 1
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing Two-Character Options ===${NC}"
|
|
|
|
# Test all two-character options are recognized
|
|
run_test "sf-deploy with -to" "./sf-deploy -to $TEST_ORG -dr nonexistent" 1 # Will fail on missing dir, but option should parse
|
|
run_test "sf-web-open with -to -pt -ur" "./sf-web-open -to $TEST_ORG -pt \"/setup\" -ur"
|
|
run_test "sf-org-create with -al" "./sf-org-create -al TestOrg -dd 1" 1 # Expected to fail but should parse options
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing Backwards Compatibility ===${NC}"
|
|
|
|
# Test long options work
|
|
run_test "sf-deploy --target-org" "./sf-deploy --target-org $TEST_ORG --directory nonexistent" 1
|
|
run_test "sf-web-open --target-org --url-only" "./sf-web-open --target-org $TEST_ORG --url-only"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-apex-run ===${NC}"
|
|
|
|
# Create a simple apex file for testing
|
|
cat > "$TEST_DIR/test.apex" << 'EOF'
|
|
System.debug('Test apex execution');
|
|
System.debug('Current user: ' + UserInfo.getName());
|
|
EOF
|
|
|
|
run_test "sf-apex-run with file" "./sf-apex-run -fl \"$TEST_DIR/test.apex\" -to $TEST_ORG"
|
|
run_test "sf-apex-run inline code" "./sf-apex-run --code \"System.debug('Inline test');\" -to $TEST_ORG"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-test-run ===${NC}"
|
|
|
|
run_test "sf-test-run basic" "./sf-test-run -to $TEST_ORG -lv RunLocalTests"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing Data Import (requires test data) ===${NC}"
|
|
|
|
# Create test CSV for import testing
|
|
cat > "$TEST_DIR/test-contacts.csv" << 'EOF'
|
|
FirstName,LastName,Email
|
|
Test,User1,testuser1@example.com
|
|
Test,User2,testuser2@example.com
|
|
EOF
|
|
|
|
run_test "sf-data-import CSV test (dry run simulation)" "echo 'Simulating: ./sf-data-import -fl \"$TEST_DIR/test-contacts.csv\" -so Contact -to $TEST_ORG'"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing Deployment Scripts ===${NC}"
|
|
|
|
# Note: We won't actually deploy, just test option parsing
|
|
run_test "sf-deploy missing source" "./sf-deploy -to $TEST_ORG" 1
|
|
run_test "sf-dry-run missing source" "./sf-dry-run -to $TEST_ORG" 1
|
|
run_test "sf-deploy conflicting options" "./sf-deploy -to $TEST_ORG -sr \"file1\" -dr \"dir1\"" 1
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Testing sf-logs-tail (quick test) ===${NC}"
|
|
|
|
# Test logs tail for a very short duration
|
|
run_test "sf-logs-tail short duration" "portable_timeout_seconds 5 ./sf-logs-tail -to $TEST_ORG --duration 1 || true"
|
|
|
|
echo ""
|
|
echo -e "${BLUE}=== Test Results Summary ===${NC}"
|
|
echo -e "${BLUE}=========================${NC}"
|
|
echo -e "Total tests run: $TESTS_RUN"
|
|
echo -e "${GREEN}Passed: $TESTS_PASSED${NC}"
|
|
echo -e "${RED}Failed: $TESTS_FAILED${NC}"
|
|
|
|
if [[ $TESTS_FAILED -gt 0 ]]; then
|
|
echo ""
|
|
echo -e "${RED}Failed tests:${NC}"
|
|
for test in "${FAILED_TESTS[@]}"; do
|
|
echo -e "${RED} - $test${NC}"
|
|
done
|
|
echo ""
|
|
echo -e "${YELLOW}Check log files in $TEST_DIR/ for detailed error information.${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
if [[ $TESTS_FAILED -eq 0 ]]; then
|
|
echo -e "${GREEN}🎉 All tests passed! All wrapper scripts are working correctly.${NC}"
|
|
exit 0
|
|
else
|
|
echo -e "${RED}❌ Some tests failed. Please review the failures above.${NC}"
|
|
exit 1
|
|
fi
|