master
sh 71 lines 2.99 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2015 Cayman Nava
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test Content-Type for channel-streaming commands"
8
9 . lib/test-lib.sh
10
11 test_init_ipfs
12
13 test_ls_cmd() {
14
15 test_expect_success "Text encoded channel-streaming command succeeds" '
16 mkdir -p testdir &&
17 echo "hello test" >testdir/test.txt &&
18 ipfs add -r testdir &&
19 curl -X POST -i "http://$API_ADDR/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=text" >actual_output
20 '
21
22 test_expect_success "Text encoded channel-streaming command output looks good" '
23 printf "HTTP/1.1 200 OK\r\n" >expected_output &&
24 printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output &&
25 printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output &&
26 printf "Content-Type: text/plain\r\n" >>expected_output &&
27 printf "Server: kubo/%s\r\n" $(ipfs version -n) >>expected_output &&
28 printf "Trailer: X-Stream-Error\r\n" >>expected_output &&
29 printf "Vary: Origin\r\n" >>expected_output &&
30 printf "X-Chunked-Output: 1\r\n" >>expected_output &&
31 printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
32 printf "\r\n" >>expected_output &&
33 echo QmRmPLc1FsPAn8F8F9DQDEYADNX5ER2sgqiokEvqnYknVW >>expected_output &&
34 cat actual_output | grep -vE Date > cleaned_output &&
35 test_cmp expected_output cleaned_output
36 '
37
38 test_expect_success "JSON encoded channel-streaming command succeeds" '
39 mkdir -p testdir &&
40 echo "hello test" >testdir/test.txt &&
41 ipfs add -r testdir &&
42 curl -X POST -i "http://$API_ADDR/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=json" >actual_output
43 '
44
45 test_expect_success "JSON encoded channel-streaming command output looks good" '
46 printf "HTTP/1.1 200 OK\r\n" >expected_output &&
47 printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output &&
48 printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length\r\n" >>expected_output &&
49 printf "Content-Type: application/json\r\n" >>expected_output &&
50 printf "Server: kubo/%s\r\n" $(ipfs version -n) >>expected_output &&
51 printf "Trailer: X-Stream-Error\r\n" >>expected_output &&
52 printf "Vary: Origin\r\n" >>expected_output &&
53 printf "X-Chunked-Output: 1\r\n" >>expected_output &&
54 printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
55 printf "\r\n" >>expected_output &&
56 cat <<-\EOF >>expected_output &&
57 {"Ref":"QmRmPLc1FsPAn8F8F9DQDEYADNX5ER2sgqiokEvqnYknVW","Err":""}
58 EOF
59 printf "\n" >> expected_output &&
60 perl -pi -e '"'"'chomp if eof'"'"' expected_output &&
61 cat actual_output | grep -vE Date > cleaned_output &&
62 test_cmp expected_output cleaned_output
63 '
64 }
65
66 # should work online (only)
67 test_launch_ipfs_daemon
68 test_ls_cmd
69 test_kill_ipfs_daemon
70
71 test_done