trying a simple shell script and fixing archives
This commit is contained in:
152
tests/integration_tests.sh
Executable file
152
tests/integration_tests.sh
Executable file
@@ -0,0 +1,152 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Integration tests for run_himalaya.sh
|
||||
|
||||
# Source test utilities
|
||||
source "$(dirname "$0")/test_utils.sh"
|
||||
|
||||
# Make sure we can find the mock himalaya command
|
||||
export PATH="$(dirname "$0"):$PATH"
|
||||
|
||||
# Common test data in real himalaya format
|
||||
NORMAL_ENVELOPE_LIST="| ID | FLAGS | SUBJECT | FROM | DATE |
|
||||
|------|-------|---------------------------------------------------------------------------------------------------|------------------------------|------------------------|
|
||||
| 1 | | Important Meeting | john@example.com | 2024-01-15 10:00+00:00|
|
||||
| 5 | * | Project Update | sarah@company.com | 2024-01-14 15:30+00:00|"
|
||||
|
||||
EXTENDED_ENVELOPE_LIST="| ID | FLAGS | SUBJECT | FROM | DATE |
|
||||
|------|-------|---------------------------------------------------------------------------------------------------|------------------------------|------------------------|
|
||||
| 1 | | Important Meeting | john@example.com | 2024-01-15 10:00+00:00|
|
||||
| 5 | * | Project Update | sarah@company.com | 2024-01-14 15:30+00:00|
|
||||
| 7 | | Weekly Standup | team@startup.com | 2024-01-13 09:00+00:00|"
|
||||
|
||||
# Test: Script with no arguments should auto-discover latest message
|
||||
test_script_auto_discover() {
|
||||
export MOCK_ENVELOPE_LIST="$NORMAL_ENVELOPE_LIST"
|
||||
|
||||
# Simulate user input: quit immediately
|
||||
local output=$(echo "q" | timeout 10 ./run_himalaya.sh 2>/dev/null)
|
||||
local exit_code=$?
|
||||
|
||||
# Check that it found the latest message (5) and attempted to read it
|
||||
if echo "$output" | grep -q "Latest message ID: 5" && echo "$output" | grep -q "Reading message 5"; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected auto-discovery of message 5, got: $output"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test: Script with valid message ID
|
||||
test_script_valid_id() {
|
||||
export MOCK_ENVELOPE_LIST="$NORMAL_ENVELOPE_LIST"
|
||||
|
||||
# Simulate user input: quit immediately
|
||||
local output=$(echo "q" | timeout 10 ./run_himalaya.sh 1 2>/dev/null)
|
||||
|
||||
# Check that it read the specified message
|
||||
if echo "$output" | grep -q "Reading message 1"; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected reading of message 1, got: $output"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test: Script with invalid message ID should fallback to latest
|
||||
test_script_invalid_id_fallback() {
|
||||
export MOCK_ENVELOPE_LIST="$NORMAL_ENVELOPE_LIST"
|
||||
export MOCK_INVALID_MESSAGE_ID="99"
|
||||
|
||||
# Simulate user input: quit immediately
|
||||
local output=$(echo "q" | timeout 10 ./run_himalaya.sh 99 2>/dev/null)
|
||||
|
||||
# Check that it fell back to latest message
|
||||
if echo "$output" | grep -q "Opening latest message: 5"; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected fallback to latest message, got: $output"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test: Empty inbox handling
|
||||
test_script_empty_inbox() {
|
||||
export MOCK_EMPTY_INBOX="true"
|
||||
|
||||
# Don't use timeout as it may interfere with exit codes
|
||||
# Use bash -c to avoid subshell exit code issues
|
||||
bash -c './run_himalaya.sh' > "$TEST_TEMP_DIR/output.txt" 2>&1
|
||||
local exit_code=$?
|
||||
local output=$(cat "$TEST_TEMP_DIR/output.txt")
|
||||
|
||||
# Should exit with error message about no messages and exit code 1
|
||||
if echo "$output" | grep -q "No messages found in inbox" && [ $exit_code -eq 1 ]; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected 'No messages found' error with exit code 1, got: $output (exit code: $exit_code)"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test: Navigation to next message
|
||||
test_navigation_next() {
|
||||
export MOCK_ENVELOPE_LIST="$EXTENDED_ENVELOPE_LIST"
|
||||
|
||||
# Simulate user input: next message, then quit
|
||||
local output=$(printf "n\nq\n" | timeout 10 ./run_himalaya.sh 1 2>/dev/null)
|
||||
|
||||
# Check that it moved to next message (5)
|
||||
if echo "$output" | grep -q "Opening next message: 5" && echo "$output" | grep -q "Reading message 5"; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected navigation to next message 5, got: $output"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test: Navigation to previous message
|
||||
test_navigation_previous() {
|
||||
export MOCK_ENVELOPE_LIST="$EXTENDED_ENVELOPE_LIST"
|
||||
|
||||
# Simulate user input: previous message, then quit
|
||||
local output=$(printf "p\nq\n" | timeout 10 ./run_himalaya.sh 7 2>/dev/null)
|
||||
|
||||
# Check that it moved to previous message (5)
|
||||
if echo "$output" | grep -q "Opening previous message: 5" && echo "$output" | grep -q "Reading message 5"; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected navigation to previous message 5, got: $output"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test: No next message available
|
||||
test_navigation_no_next() {
|
||||
export MOCK_ENVELOPE_LIST="$NORMAL_ENVELOPE_LIST"
|
||||
|
||||
# Simulate user input: next message (should fail), then quit
|
||||
local output=$(printf "n\nq\n" | timeout 10 ./run_himalaya.sh 5 2>/dev/null)
|
||||
|
||||
# Check that it shows "No next message available"
|
||||
if echo "$output" | grep -q "No next message available"; then
|
||||
return 0
|
||||
else
|
||||
echo "Expected 'No next message available', got: $output"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Run all tests
|
||||
echo "Running integration tests for run_himalaya.sh..."
|
||||
echo
|
||||
|
||||
run_test "Script auto-discovers latest message when no args" test_script_auto_discover
|
||||
run_test "Script reads specified valid message ID" test_script_valid_id
|
||||
run_test "Script falls back to latest when invalid ID provided" test_script_invalid_id_fallback
|
||||
run_test "Script handles empty inbox gracefully" test_script_empty_inbox
|
||||
run_test "Navigation to next message works" test_navigation_next
|
||||
run_test "Navigation to previous message works" test_navigation_previous
|
||||
run_test "No next message available handled gracefully" test_navigation_no_next
|
||||
|
||||
print_test_summary
|
||||
Reference in New Issue
Block a user