Added Sharness test for HTTP Gateway
Mildred Ki'Lya committed
Jan 30, 2015 at 14:04 UTC
51af53d8f752d793bd2736d0ec6af63801a35ef7
2 files changed
+116
test/sharness/lib/test-lib.sh
+10
@@ -64,6 +64,16 @@ test_wait_output_n_lines_60_sec() {
64
test_cmp "expected_waitn" "actual_waitn"
65
}
66
67
+test_wait_open_tcp_port_10_sec() {
68
+ for i in 1 2 3 4 5 6 7 8 9 10; do
69
+ if [ $(ss -lt "sport == :$1" | wc -l) -gt 1 ]; then
70
+ return 0
71
+ fi
72
+ sleep 1
73
+ done
74
+ return 1
75
+}
76
+
77
test_init_ipfs() {
78
79
test_expect_success "ipfs init succeeds" '
test/sharness/t0100-http-gateway.sh
new
+106
@@ -0,0 +1,106 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2014 Christian Couder
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test HTTP Gateway"
8
+
9
+exec 3>&1 4>&2
10
+. lib/test-lib.sh
11
+
12
+test_expect_success "Configure http gateway" '
13
+ export IPFS_PATH="$PWD/.go-ipfs";
14
+ if ! [ -e ../ipfs-path ]; then
15
+ IPFS_PATH="$PWD/../ipfs-path" ipfs init;
16
+ fi;
17
+ cp -R ../ipfs-path "$IPFS_PATH" &&
18
+ ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/5002 &&
19
+ ipfs config -bool Gateway.Writable true
20
+'
21
+
22
+test_expect_success "ipfs daemon --init launches and listen to TCP port 5002" '
23
+ export IPFS_PATH="$PWD/.go-ipfs" &&
24
+ ipfs daemon 2>&1 >actual_init &
25
+ IPFS_PID=$(ps | grep ipfs | awk "{print \$1}");
26
+ test_wait_open_tcp_port_10_sec 5002
27
+'
28
+
29
+test_expect_success "HTTP gateway gives access to sample file" '
30
+ curl -s -o welcome http://localhost:5002/ipfs/QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ &&
31
+ grep "Hello and Welcome to IPFS!" welcome
32
+'
33
+
34
+test_expect_success "HTTP POST file gives Hash" '
35
+ echo "$RANDOM" >infile
36
+ curl -svX POST --data-binary @infile http://localhost:5002/ipfs/ 2>curl.out &&
37
+ grep "HTTP/1.1 201 Created" curl.out
38
+'
39
+
40
+test_expect_success "We can HTTP GET file just created" '
41
+ path=$(grep Location curl.out | cut -d" " -f3- | tr -d "\r")
42
+ curl -so outfile http://localhost:5002$path &&
43
+ diff -u infile outfile
44
+'
45
+
46
+test_expect_success "HTTP PUT empty directory" '
47
+ echo "PUT http://localhost:5002/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/" &&
48
+ curl -svX PUT http://localhost:5002/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/ 2>curl.out &&
49
+ cat curl.out &&
50
+ grep "Ipfs-Hash: QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" curl.out &&
51
+ grep "Location: /ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/" curl.out &&
52
+ grep "HTTP/1.1 201 Created" curl.out
53
+'
54
+
55
+test_expect_success "HTTP GET empty directory" '
56
+ echo "GET http://localhost:5002/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/" &&
57
+ curl -so outfile http://localhost:5002/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/ 2>curl.out &&
58
+ grep "Index of /ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/" outfile
59
+'
60
+
61
+test_expect_success "HTTP PUT file to construct a hierarchy" '
62
+ echo "$RANDOM" >infile
63
+ echo "PUT http://localhost:5002/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/test.txt" &&
64
+ curl -svX PUT --data-binary @infile http://localhost:5002/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/test.txt 2>curl.out &&
65
+ grep "HTTP/1.1 201 Created" curl.out &&
66
+ grep Location curl.out
67
+'
68
+
69
+test_expect_success "We can HTTP GET file just created" '
70
+ path=$(grep Location curl.out | cut -d" " -f3- | tr -d "\r");
71
+ echo "$path" = "${path%/test.txt}/test.txt";
72
+ [ "$path" = "${path%/test.txt}/test.txt" ] &&
73
+ echo "GET http://localhost:5002$path" &&
74
+ curl -so outfile http://localhost:5002$path &&
75
+ diff -u infile outfile
76
+'
77
+
78
+test_expect_success "HTTP PUT file to append to existing hierarchy" '
79
+ echo "$RANDOM" >infile2;
80
+ echo "PUT http://localhost:5002${path%/test.txt}/test/test.txt" &&
81
+ curl -svX PUT --data-binary @infile2 http://localhost:5002${path%/test.txt}/test/test.txt 2>curl.out &&
82
+ grep "HTTP/1.1 201 Created" curl.out &&
83
+ grep Location curl.out
84
+'
85
+
86
+test_expect_success "We can HTTP GET file just created" '
87
+ path=$(grep Location curl.out | cut -d" " -f3- | tr -d "\r");
88
+ [ "$path" = "${path%/test/test.txt}/test/test.txt" ] &&
89
+ echo "GET http://localhost:5002$path" &&
90
+ curl -so outfile2 http://localhost:5002$path &&
91
+ diff -u infile2 outfile2 &&
92
+ echo "GET http://localhost:5002${path%/test/test.txt}/test.txt" &&
93
+ curl -so outfile http://localhost:5002${path%/test/test.txt}/test.txt &&
94
+ diff -u infile outfile
95
+'
96
+
97
+test_expect_success "daemon is still running" '
98
+ echo IPFS_PID=$IPFS_PID;
99
+ kill -15 $IPFS_PID
100
+'
101
+
102
+test_expect_success "'ipfs daemon' can be killed" '
103
+ test_kill_repeat_10_sec $IPFS_PID
104
+'
105
+
106
+test_done