-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·86 lines (66 loc) · 2.13 KB
/
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
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
#!/bin/bash
set -e
execute_cmd()
{
echo "Executing $*"
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 20222 git@localhost "$*"
}
expect_pass()
{
if "$@" > /dev/null 2>&1; then
echo -en "$*\t"; tput setaf 2; echo "OK"; tput sgr0
else
echo -en "$*\t"; tput setaf 1; echo "KO"; tput sgr0
exit 1
fi
}
expect_fail()
{
if ! "$@" > /dev/null 2>&1; then
echo -en "$*\t"; tput setaf 2; echo "OK"; tput sgr0
else
echo -en "$*\t"; tput setaf 1; echo "KO"; tput sgr0
exit 1
fi
}
test_folder=$(mktemp -d)
echo "test folder: $test_folder"
mkdir "$test_folder/ssh"
mkdir "$test_folder/git"
cat > "$test_folder/config.yml" << EOM
external_hostname: localhost
external_port: 20222
accounts:
- user: git
uid: 4000
keys:
EOM
echo " - \"$(cat ~/.ssh/id_rsa.pub)\"" >> "$test_folder/config.yml"
docker stop test-minimal-git-server > /dev/null 2>&1 || true
docker rm test-minimal-git-server > /dev/null 2>&1 || true
docker build -t test-minimal-git-server .
docker run -v "${test_folder}"/ssh:/srv/ssh -v "${test_folder}"/git:/srv/git -v "${test_folder}"/config.yml:/srv/config.yml:ro \
--name test-minimal-git-server -d -p 20222:22 test-minimal-git-server
sleep 5 # wait container to be ready
expect_pass execute_cmd "create abc123"
expect_fail execute_cmd "create abc123" # test cannot override
expect_pass execute_cmd "exists abc123"
# test rename
expect_pass execute_cmd "rename abc123 abc456"
expect_fail execute_cmd "exists abc123"
expect_pass execute_cmd "exists abc456"
# test rename to subfolder
expect_pass execute_cmd "rename abc456 toto/abc456"
expect_fail execute_cmd "exists abc456"
expect_pass execute_cmd "exists toto/abc456"
expect_pass execute_cmd "show toto/abc456"
expect_fail execute_cmd "show toto"
expect_fail execute_cmd "show 123"
# test remove
expect_pass execute_cmd "remove toto/abc456"
expect_fail execute_cmd "exists toto/abc456"
# test remove parent folder
expect_pass execute_cmd "create toto/abc/123"
expect_pass execute_cmd "remove toto"
expect_fail execute_cmd "exists toto/abc/123"
tput setaf 2; echo "All test OK"; tput sgr0