-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmanage_domains_test.sh
47 lines (39 loc) · 1.36 KB
/
manage_domains_test.sh
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
#!/bin/bash
# Create temporary test directory
TEST_DIR=$(mktemp -d)
trap 'rm -rf "$TEST_DIR"' EXIT
# Source files
list_file="../list"
inactive_file="../inactive"
# Test files
test_list_file="${TEST_DIR}/test_list"
test_inactive_file="${TEST_DIR}/test_inactive"
# Backup original files
cp "$list_file" "$test_list_file"
cp "$inactive_file" "$test_inactive_file"
# Test adding a new domain
./manage_domains.sh add "newdomain.com"
if grep -q "^newdomain.com$" "$test_list_file"; then
echo "Test add domain: PASSED"
else
echo "Test add domain: FAILED"
fi
# Test moving an inactive domain
./manage_domains.sh move "newdomain.com"
if grep -q "^newdomain.com$" "$test_inactive_file" && ! grep -q "^newdomain.com$" "$test_list_file"; then
echo "Test move domain: PASSED"
else
echo "Test move domain: FAILED"
fi
# Test maintaining file sorting and comments
./manage_domains.sh add "anotherdomain.com"
./manage_domains.sh move "anotherdomain.com"
if diff -u <(grep -v -E '^(#|$)' "$test_list_file" | sort) <(grep -v -E '^(#|$)' "$test_list_file") && \
diff -u <(grep -v -E '^(#|$)' "$test_inactive_file" | sort) <(grep -v -E '^(#|$)' "$test_inactive_file"); then
echo "Test file sorting and comments: PASSED"
else
echo "Test file sorting and comments: FAILED"
fi
# Restore original files
mv "$test_list_file" "$list_file"
mv "$test_inactive_file" "$inactive_file"