Skip to content

Commit c41d993

Browse files
committed
test: add test cases
1 parent 7d4b65e commit c41d993

20 files changed

+119
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.*/
22
/output
33
/test/bin/
4+
/test/**/*.tmp

test/case/001.basic.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -r "$fs"/vhost1 &
6+
sleep 0.05 # wait server ready
67

7-
file1=$(http_get_body 127.0.0.1:3003/file1.txt)
8+
file1=$(curl_get_body http://127.0.0.1:3003/file1.txt)
89
assert "$file1" 'vhost1/file1.txt'
910

1011
kill %1

test/case/002.vhost.bash

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -r "$fs"/vhost1 --hostname=127.0.0.1 ,, -l 3003 -r "$fs"/vhost2 --hostname=127.0.0.2 &
6+
sleep 0.05 # wait server ready
67

7-
vh1file1=$(http_get_body 127.0.0.1:3003/file1.txt)
8+
vh1file1=$(curl_get_body http://127.0.0.1:3003/file1.txt)
89
assert "$vh1file1" 'vhost1/file1.txt'
910

10-
vh2file1=$(http_get_body 127.0.0.2:3003/file1.txt)
11+
vh2file1=$(curl_get_body http://127.0.0.2:3003/file1.txt)
1112
assert "$vh2file1" 'vhost2/file1.txt'
1213

1314
kill %1

test/case/003.vhost.tls.bash

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -r "$fs"/vhost1 --hostname=127.0.0.1 -c "$cert"/example.crt -k "$cert"/example.key ,, -l 3003 -r "$fs"/vhost2 --hostname=127.0.0.2 -c "$cert"/localhost.crt -k "$cert"/localhost.key &
6+
sleep 0.05 # wait server ready
67

7-
vh1file1=$(https_get_body 127.0.0.1:3003/file1.txt)
8+
vh1file1=$(curl_get_body https://127.0.0.1:3003/file1.txt)
89
assert "$vh1file1" 'vhost1/file1.txt'
910

10-
vh2file1=$(https_get_body 127.0.0.2:3003/file1.txt)
11+
vh2file1=$(curl_get_body https://127.0.0.2:3003/file1.txt)
1112
assert "$vh2file1" 'vhost2/file1.txt'
1213

1314
kill %1

test/case/004.alias.bash

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
source "$root"/lib.bash
44

5-
"$ghfs" -l 3003 -r "$fs"/vhost1 -a :world:"$fs"/vhost1/go :/not/exist/name:"$fs"/vhost1/yes &
5+
"$ghfs" -l 3003 -r "$fs"/vhost1 -a :world:"$fs"/vhost1/go :/not/exist/name:"$fs"/vhost1/yes -E '' &
6+
sleep 0.05 # wait server ready
67

7-
file1=$(http_get_body 127.0.0.1:3003/file1.txt)
8+
file1=$(curl_get_body http://127.0.0.1:3003/file1.txt)
89
assert "$file1" 'vhost1/file1.txt'
910

10-
hello=$(http_get_body 127.0.0.1:3003/hello/index.txt)
11+
hello=$(curl_get_body http://127.0.0.1:3003/hello/index.txt)
1112
assert "$hello" 'vhost1/hello/index.txt'
1213

13-
go=$(http_get_body 127.0.0.1:3003/world/index.txt)
14+
go=$(curl_get_body http://127.0.0.1:3003/world/index.txt)
1415
assert "$go" 'vhost1/go/index.txt'
1516

16-
yes=$(http_get_body 127.0.0.1:3003/not/exist/name/index.txt)
17+
status=$(curl_get_status http://127.0.0.1:3003/not)
18+
assert "$status" '404'
19+
20+
status=$(curl_get_status http://127.0.0.1:3003/not/exist)
21+
assert "$status" '404'
22+
23+
yes=$(curl_get_body http://127.0.0.1:3003/not/exist/name/index.txt)
1724
assert "$yes" 'vhost1/yes/index.txt'
1825

1926
kill %1

test/case/005.alias.empty.root.bash

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -R -a :world:"$fs"/vhost1/go :/not/exist/name:"$fs"/vhost1/yes &
6+
sleep 0.05 # wait server ready
67

7-
file1status=$(http_get_status 127.0.0.1:3003/file1.txt | head -n 1 | cut -d ' ' -f 2)
8+
file1status=$(curl_get_status http://127.0.0.1:3003/file1.txt | head -n 1 | cut -d ' ' -f 2)
89
assert "$file1status" '404'
910

10-
file1headstatus=$(http_head_status 127.0.0.1:3003/file1.txt | head -n 1 | cut -d ' ' -f 2)
11+
file1headstatus=$(curl_head_status http://127.0.0.1:3003/file1.txt | head -n 1 | cut -d ' ' -f 2)
1112
assert "$file1headstatus" '404'
1213

13-
hellostatus=$(http_get_status 127.0.0.1:3003/hello/index.txt | head -n 1 | cut -d ' ' -f 2)
14+
hellostatus=$(curl_get_status http://127.0.0.1:3003/hello/index.txt | head -n 1 | cut -d ' ' -f 2)
1415
assert "$hellostatus" '404'
1516

16-
helloheadstatus=$(http_head_status 127.0.0.1:3003/hello/index.txt | head -n 1 | cut -d ' ' -f 2)
17+
helloheadstatus=$(curl_head_status http://127.0.0.1:3003/hello/index.txt | head -n 1 | cut -d ' ' -f 2)
1718
assert "$helloheadstatus" '404'
1819

19-
go=$(http_get_body 127.0.0.1:3003/world/index.txt)
20+
go=$(curl_get_body http://127.0.0.1:3003/world/index.txt)
2021
assert "$go" 'vhost1/go/index.txt'
2122

22-
yes=$(http_get_body 127.0.0.1:3003/not/exist/name/index.txt)
23+
yes=$(curl_get_body http://127.0.0.1:3003/not/exist/name/index.txt)
2324
assert "$yes" 'vhost1/yes/index.txt'
2425

2526
kill %1

test/case/006.auth.bash

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -r "$fs"/vhost1 --auth /hello --user alice:AliceSecret &
6+
sleep 0.05 # wait server ready
67

7-
yesstatus=$(http_get_status 127.0.0.1:3003/yes/)
8+
yesstatus=$(curl_get_status http://127.0.0.1:3003/yes/)
89
assert "$yesstatus" '200'
910

10-
hellostatus=$(http_get_status 127.0.0.1:3003/hello/)
11+
hellostatus=$(curl_get_status http://127.0.0.1:3003/hello/)
1112
assert "$hellostatus" '401'
1213

13-
userhellostatus=$(http_get_status alice:[email protected]:3003/hello/)
14+
userhellostatus=$(curl_get_status http://alice:[email protected]:3003/hello/)
1415
assert "$userhellostatus" '200'
1516

16-
userhelloheadstatus=$(http_head_status alice:[email protected]:3003/hello/)
17+
userhelloheadstatus=$(curl_head_status http://alice:[email protected]:3003/hello/)
1718
assert "$userhelloheadstatus" '200'
1819

1920
kill %1

test/case/007.dir.index.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -r "$fs"/vhost1 -I index.txt &
6+
sleep 0.05 # wait server ready
67

7-
yes=$(http_get_body 127.0.0.1:3003/yes)
8+
yes=$(curl_get_body http://127.0.0.1:3003/yes)
89
assert "$yes" 'vhost1/yes/index.txt'
910

1011
kill %1

test/case/008.alias.dir.index.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
source "$root"/lib.bash
44

55
"$ghfs" -l 3003 -r "$fs"/vhost1 -I index.txt -a :/hello/index.txt:"$fs"/vhost1/world/index.txt &
6+
sleep 0.05 # wait server ready
67

7-
world=$(http_get_body 127.0.0.1:3003/hello)
8+
world=$(curl_get_body http://127.0.0.1:3003/hello)
89
assert "$world" 'vhost1/world/index.txt'
910

1011
kill %1

test/case/009.upload.bash

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
cleanup() {
4+
rm -f "$fs"/uploaded/[12]/*.tmp
5+
}
6+
7+
source "$root"/lib.bash
8+
9+
"$ghfs" -l 3003 -r "$fs"/uploaded --upload /1 --upload-dir "$fs"/uploaded/2 &
10+
sleep 0.05 # wait server ready
11+
cleanup
12+
13+
content1='uploaded/1/uploaded.tmp'
14+
curl_upload_content http://127.0.0.1:3003/1 files "$content1" uploaded.tmp
15+
uploaded1=$(cat "$fs"/uploaded/1/uploaded.tmp)
16+
assert "$uploaded1" "$content1"
17+
18+
content2='uploaded/2/uploaded.tmp'
19+
curl_upload_content http://127.0.0.1:3003/2 files "$content2" uploaded.tmp
20+
uploaded2=$(cat "$fs"/uploaded/2/uploaded.tmp)
21+
assert "$uploaded2" "$content2"
22+
23+
cleanup
24+
kill %1

0 commit comments

Comments
 (0)