summaryrefslogtreecommitdiff
path: root/test/test_exit_codes.sh
blob: 742e2ed2a683f36c41a9b6ffb489b497c6d3334e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

# Test script to verify gitsyncer exit codes
echo "Testing gitsyncer exit codes..."

GITSYNCER="../gitsyncer"

# Test 1: Successful operation should exit 0
echo -n "Test 1 - Successful operation (--version): "
$GITSYNCER --version >/dev/null 2>&1
if [ $? -eq 0 ]; then
    echo "PASS (exit code 0)"
else
    echo "FAIL (expected 0, got $?)"
fi

# Test 2: No arguments should exit 1
echo -n "Test 2 - No arguments (show usage): "
$GITSYNCER >/dev/null 2>&1
if [ $? -eq 1 ]; then
    echo "PASS (exit code 1)"
else
    echo "FAIL (expected 1, got $?)"
fi

# Test 3: Invalid config file should exit 1
echo -n "Test 3 - Invalid config file: "
$GITSYNCER --config /nonexistent/config.json --list-orgs >/dev/null 2>&1
if [ $? -eq 1 ]; then
    echo "PASS (exit code 1)"
else
    echo "FAIL (expected 1, got $?)"
fi

# Test 4: Sync non-existent repo should exit 1
echo -n "Test 4 - Sync non-existent repo: "
$GITSYNCER --sync nonexistentrepo123456 >/dev/null 2>&1
if [ $? -eq 1 ]; then
    echo "PASS (exit code 1)"
else
    echo "FAIL (expected 1, got $?)"
fi

# Test 5: Successful list operation should exit 0
echo -n "Test 5 - Successful list operation: "
$GITSYNCER --list-orgs >/dev/null 2>&1
if [ $? -eq 0 ]; then
    echo "PASS (exit code 0)"
else
    echo "FAIL (expected 0, got $?)"
fi

# Test 6: Test GitHub token without token should exit 1
echo -n "Test 6 - Test GitHub token (invalid): "
GITHUB_TOKEN="invalid" $GITSYNCER --test-github-token >/dev/null 2>&1
if [ $? -eq 1 ]; then
    echo "PASS (exit code 1)"
else
    echo "FAIL (expected 1, got $?)"
fi

echo ""
echo "Summary: Exit codes are used correctly"
echo "- Exit 0: Successful operations"
echo "- Exit 1: Errors and invalid usage"