Files
nextcloud-integration/quick-test.sh
T
WLTBAgent e49020b193 Add build verification and test credential checking
- Build script now shows summary of embedded credentials after build
- quick-test.sh now checks if binary has credentials before running
- This prevents the "dial tcp :143" empty server error

Tests if help output shows empty string in default values.
2026-02-23 22:30:57 +00:00

121 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
# Quick Test Script for nextcloud-mail
# Usage: ./quick-test.sh
set -e
USERNAME="${1:-wltbagent@shortcutsolutions.net}"
TEST_DIR="/tmp/mail-tests"
echo "========================================="
echo "nextcloud-mail Quick Test Suite"
echo "========================================="
echo ""
# Check if binary has credentials before running
echo "Checking binary credentials..."
if ~/bin/nextcloud-mail --help 2>&1 | grep -q '"imap-server".*"\"\"'; then
echo "❌ Error: nextcloud-mail binary was built with empty credentials!"
echo " Please run ./build.sh again and provide valid IMAP/SMTP credentials."
echo ""
echo "Current binary shows:"
~/bin/nextcloud-mail --help 2>&1 | grep -A2 '"imap-server"'
echo ""
exit 1
fi
echo "✓ Binary has credentials configured"
echo "Username: $USERNAME"
echo "Test Directory: $TEST_DIR"
echo ""
# Create test directory
mkdir -p "$TEST_DIR"
echo "✓ Test directory created: $TEST_DIR"
echo ""
# Test 1: List folders
echo "Test 1: List folders"
echo "Running: ~/bin/nextcloud-mail --op list-folders"
~/bin/nextcloud-mail --op list-folders
echo ""
# Test 2: List messages
echo "Test 2: List messages in INBOX"
echo "Running: ~/bin/nextcloud-mail --op list-messages --folder INBOX --page 1 --page-size 5"
~/bin/nextcloud-mail --op list-messages --folder INBOX --page 1 --page-size 5
echo ""
# Test 3: Send test email
echo "Test 3: Send test email to self"
TEST_SUBJECT="nextcloud-mail Test - $(date +%s)"
echo "Running: ~/bin/nextcloud-mail --op send-email --from $USERNAME --to $USERNAME --subject '$TEST_SUBJECT'"
~/bin/nextcloud-mail --op send-email \
--from "$USERNAME" \
--to "$USERNAME" \
--subject "$TEST_SUBJECT" \
--body "This is an automated test from nextcloud-mail tool."
echo ""
# Wait for email to arrive
echo "Waiting 5 seconds for email to arrive..."
sleep 5
echo ""
# Test 4: Search for test email
echo "Test 4: Search for test email"
echo "Running: ~/bin/nextcloud-mail --op search --folder INBOX --query '$TEST_SUBJECT'"
~/bin/nextcloud-mail --op search --folder INBOX --query "$TEST_SUBJECT"
echo ""
# Test 5: Send email with attachment
echo "Test 5: Send email with attachment"
echo "Creating test attachment..."
echo "This is a test attachment from nextcloud-mail." > "$TEST_DIR/attachment.txt"
echo "Running: ~/bin/nextcloud-mail --op send-email --from $USERNAME --to $USERNAME --subject 'Test with attachment' --attachments $TEST_DIR/attachment.txt"
~/bin/nextcloud-mail --op send-email \
--from "$USERNAME" \
--to "$USERNAME" \
--subject "Test with attachment - $(date +%s)" \
--body "Email with one attachment." \
--attachments "$TEST_DIR/attachment.txt"
echo ""
# Wait for attachment email
echo "Waiting 5 seconds for attachment email to arrive..."
sleep 5
echo ""
# Test 6: Get message with attachment
echo "Test 6: Get message and list attachments"
echo "Finding recent message..."
UID=$(~/bin/nextcloud-mail --op list-messages --folder INBOX --page 1 --page-size 1 | grep "UID:" | awk '{print $2}')
if [ -n "$UID" ]; then
echo "Found UID: $UID"
echo "Running: ~/bin/nextcloud-mail --op get-message --folder INBOX --uids $UID --list-attachments"
~/bin/nextcloud-mail --op get-message --folder INBOX --uids "$UID" --list-attachments
# Test 7: Save attachments
echo ""
echo "Test 7: Save attachments"
mkdir -p "$TEST_DIR/downloads"
echo "Running: ~/bin/nextcloud-mail --op get-message --folder INBOX --uids $UID --save-attachments --save-dir $TEST_DIR/downloads"
~/bin/nextcloud-mail --op get-message --folder INBOX --uids "$UID" \
--save-attachments --save-dir "$TEST_DIR/downloads"
# Verify files were saved
echo ""
echo "Downloaded files:"
ls -lh "$TEST_DIR/downloads"
else
echo "⚠ Could not find message UID for attachment test"
fi
echo ""
echo "========================================="
echo "Quick Test Suite Complete!"
echo "========================================="
echo ""
echo "Test artifacts in: $TEST_DIR"
echo "For full testing, see: TEST-PLAN.md"