forked from dotandev/hintents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_update_checker.sh
More file actions
101 lines (85 loc) · 2.62 KB
/
test_update_checker.sh
File metadata and controls
101 lines (85 loc) · 2.62 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright (c) Hintents Authors.
# SPDX-License-Identifier: Apache-2.0
#!/bin/bash
// Copyright (c) 2026 dotandev
// SPDX-License-Identifier: MIT OR Apache-2.0
set -e
echo "=== Update Checker Integration Tests ==="
echo ""
# Clean slate
echo "1. Cleaning cache and config..."
rm -rf ~/.cache/erst ~/.config/erst
echo " [OK] Clean"
echo ""
# Build with old version
echo "2. Building with old version (v0.0.1)..."
go build -ldflags "-X main.Version=v0.0.1" -o erst_test ./cmd/erst
echo " [OK] Built"
echo ""
# First run - should check (but will fail silently due to no releases)
echo "3. First run (checking update checker runs)..."
timeout 10 ./erst_test version > /dev/null 2>&1 || true
sleep 2 # Wait for goroutine
# Note: Cache won't be created because GitHub has no releases (404)
# This is expected behavior - update checker fails silently
if [ -f ~/.cache/erst/last_update_check ]; then
echo " [OK] Cache file created (GitHub has releases)"
else
echo " [INFO] Cache file not created (expected - no GitHub releases yet)"
echo " [OK] Update checker ran without errors"
fi
echo ""
# Test opt-out
echo "4. Testing opt-out..."
ERST_NO_UPDATE_CHECK=1 ./erst_test version > /dev/null 2>&1
echo " [OK] Opt-out works (no errors)"
echo ""
# Test with config file
echo "5. Testing config file opt-out..."
mkdir -p ~/.config/erst
cat > ~/.config/erst/config.yaml << 'EOF'
check_for_updates: false
EOF
./erst_test version > /dev/null 2>&1
echo " [OK] Config file opt-out works"
rm ~/.config/erst/config.yaml
echo ""
# Test with current version
echo "6. Building with future version (v999.0.0)..."
go build -ldflags "-X main.Version=v999.0.0" -o erst_test ./cmd/erst
./erst_test version > output.txt 2>&1
if grep -q "new version" output.txt; then
echo " [FAIL] FAIL: Notification shown when already latest"
cat output.txt
exit 1
else
echo " [OK] No false notification"
fi
echo ""
# Test version command works
echo "7. Testing version command..."
VERSION_OUTPUT=$(./erst_test version)
if echo "$VERSION_OUTPUT" | grep -q "v999.0.0"; then
echo " [OK] Version command works: $VERSION_OUTPUT"
else
echo " [FAIL] FAIL: Version command output incorrect"
echo " Got: $VERSION_OUTPUT"
exit 1
fi
echo ""
# Test help command
echo "8. Testing help command..."
if ./erst_test --help | grep -q "version"; then
echo " [OK] Help command shows version"
else
echo " [FAIL] FAIL: Help command doesn't show version"
exit 1
fi
echo ""
# Cleanup
echo "9. Cleaning up..."
rm -f erst_test output.txt
rm -rf ~/.config/erst
echo " [OK] Cleanup complete"
echo ""
echo "=== All Integration Tests Passed [OK] ==="