-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathremove_session_test.sh
More file actions
executable file
·71 lines (51 loc) · 1.21 KB
/
remove_session_test.sh
File metadata and controls
executable file
·71 lines (51 loc) · 1.21 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
#!/usr/bin/env bash
set -e
source test/helpers/sqlite_fixture.sh
TMP_DB=$(mktemp)
setup() {
rm -f "$TMP_DB"
create_test_db "$TMP_DB"
}
teardown() {
rm -f "$TMP_DB"
}
test_remove_existing_session() {
setup
./remove_session --db "$TMP_DB" --session-id s1
COUNT=$(count_sessions "$TMP_DB")
if [ "$COUNT" -ne 1 ]; then
echo "Expected 1 session remaining"
exit 1
fi
teardown
}
test_remove_nonexistent_session() {
setup
./remove_session --db "$TMP_DB" --session-id does_not_exist
COUNT=$(count_sessions "$TMP_DB")
if [ "$COUNT" -ne 2 ]; then
echo "Expected 2 sessions remaining"
exit 1
fi
teardown
}
test_idempotency() {
setup
./remove_session --db "$TMP_DB" --session-id s1
./remove_session --db "$TMP_DB" --session-id s1
COUNT=$(count_sessions "$TMP_DB")
if [ "$COUNT" -ne 1 ]; then
echo "Idempotency failed"
exit 1
fi
teardown
}
test_missing_db() {
./remove_session --db missing.db --session-id s1 && exit 1 || [ $? -eq 1 ]
}
echo "Running remove_session tests..."
test_remove_existing_session
test_remove_nonexistent_session
test_idempotency
test_missing_db
echo "All tests passed."