@cryptotaxi247 / kubo / commits / c60163183

t0090: test ipfs get offline as well as online

To do that the current tests are move inside a test_get_cmd() function. This function is then first called before running the daemon for offline tests and then after starting the daemon for online tests. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Mar 21, 2015 at 09:14 UTC c60163183a0351498a2e9c03c117ec34dc2fa697
1 file changed +109 -100
test/sharness/t0090-get.sh
+109 -100
@@ -9,107 +9,116 @@ test_description="Test get command"
9 . lib/test-lib.sh
10
11 test_init_ipfs
12 -test_launch_ipfs_daemon
13 -
14 -test_expect_success "'ipfs get --help' succeeds" '
15 - ipfs get --help >actual
16 -'
17 -
18 -test_expect_success "'ipfs get --help' output looks good" '
19 - egrep "ipfs get.*<ipfs-path>" actual >/dev/null ||
20 - test_fsh cat actual
21 -'
22 -
23 -test_expect_success "ipfs get succeeds" '
24 - echo "Hello Worlds!" >data &&
25 - HASH=`ipfs add -q data` &&
26 - ipfs get "$HASH" >actual
27 -'
28 -
29 -test_expect_success "ipfs get output looks good" '
30 - printf "%s\n\n" "Saving file(s) to $HASH" >expected &&
31 - test_cmp expected actual
32 -'
33 -
34 -test_expect_success "ipfs get file output looks good" '
35 - test_cmp "$HASH" data
36 -'
37 -
38 -test_expect_success "ipfs get errors when trying to overwrite a file" '
39 - test_must_fail ipfs get "$HASH" >actual &&
40 - rm "$HASH"
41 -'
42 -
43 -test_expect_success "ipfs get -a succeeds" '
44 - ipfs get "$HASH" -a >actual
45 -'
46 -
47 -test_expect_success "ipfs get -a output looks good" '
48 - printf "%s\n\n" "Saving archive to $HASH.tar" >expected &&
49 - test_cmp expected actual
50 -'
51 -
52 -test_expect_success "ipfs get -a archive output is valid" '
53 - tar -xf "$HASH".tar &&
54 - test_cmp "$HASH" data &&
55 - rm "$HASH".tar &&
56 - rm "$HASH"
57 -'
58 -
59 -test_expect_success "ipfs get -a -C succeeds" '
60 - ipfs get "$HASH" -a -C >actual
61 -'
62 -
63 -test_expect_success "ipfs get -a -C output looks good" '
64 - printf "%s\n\n" "Saving archive to $HASH.tar.gz" >expected &&
65 - test_cmp expected actual
66 -'
67 -
68 -# TODO(mappum)
69 -test_expect_failure "gzipped tar archive output is valid" '
70 - tar -zxf "$HASH".tar.gz &&
71 - test_cmp "$HASH" data &&
72 - rm "$HASH".tar.gz &&
73 - rm "$HASH"
74 -'
75 -
76 -test_expect_success "ipfs get succeeds (directory)" '
77 - mkdir dir &&
78 - touch dir/a &&
79 - mkdir dir/b &&
80 - echo "Hello, Worlds!" >dir/b/c &&
81 - HASH2=`ipfs add -r -q dir | tail -n 1` &&
82 - ipfs get "$HASH2" >actual
83 -'
84 -
85 -test_expect_success "ipfs get output looks good (directory)" '
86 - printf "%s\n\n" "Saving file(s) to $HASH2" >expected &&
87 - test_cmp expected actual
88 -'
89 -
90 -test_expect_success "ipfs get output is valid (directory)" '
91 - test_cmp dir/a "$HASH2"/a &&
92 - test_cmp dir/b/c "$HASH2"/b/c &&
93 - rm -r "$HASH2"
94 -'
95 -
96 -test_expect_success "ipfs get -a -C succeeds (directory)" '
97 - ipfs get "$HASH2" -a -C >actual
98 -'
99 -
100 -test_expect_success "ipfs get -a -C output looks good (directory)" '
101 - printf "%s\n\n" "Saving archive to $HASH2.tar.gz" >expected &&
102 - test_cmp expected actual
103 -'
104 -
105 -# TODO(mappum)
106 -test_expect_failure "gzipped tar archive output is valid (directory)" '
107 - tar -zxf "$HASH2".tar.gz &&
108 - test_cmp dir/a "$HASH2"/a &&
109 - test_cmp dir/b/c "$HASH2"/b/c &&
110 - rm -r "$HASH2"
111 -'
12
13 +# we use a function so that we can run it both offline + online
14 +test_get_cmd() {
15 +
16 + test_expect_success "'ipfs get --help' succeeds" '
17 + ipfs get --help >actual
18 + '
19 +
20 + test_expect_success "'ipfs get --help' output looks good" '
21 + egrep "ipfs get.*<ipfs-path>" actual >/dev/null ||
22 + test_fsh cat actual
23 + '
24 +
25 + test_expect_success "ipfs get succeeds" '
26 + echo "Hello Worlds!" >data &&
27 + HASH=`ipfs add -q data` &&
28 + ipfs get "$HASH" >actual
29 + '
30 +
31 + test_expect_success "ipfs get output looks good" '
32 + printf "%s\n\n" "Saving file(s) to $HASH" >expected &&
33 + test_cmp expected actual
34 + '
35 +
36 + test_expect_success "ipfs get file output looks good" '
37 + test_cmp "$HASH" data
38 + '
39 +
40 + test_expect_success "ipfs get errors when trying to overwrite a file" '
41 + test_must_fail ipfs get "$HASH" >actual &&
42 + rm "$HASH"
43 + '
44 +
45 + test_expect_success "ipfs get -a succeeds" '
46 + ipfs get "$HASH" -a >actual
47 + '
48 +
49 + test_expect_success "ipfs get -a output looks good" '
50 + printf "%s\n\n" "Saving archive to $HASH.tar" >expected &&
51 + test_cmp expected actual
52 + '
53 +
54 + test_expect_success "ipfs get -a archive output is valid" '
55 + tar -xf "$HASH".tar &&
56 + test_cmp "$HASH" data &&
57 + rm "$HASH".tar &&
58 + rm "$HASH"
59 + '
60 +
61 + test_expect_success "ipfs get -a -C succeeds" '
62 + ipfs get "$HASH" -a -C >actual
63 + '
64 +
65 + test_expect_success "ipfs get -a -C output looks good" '
66 + printf "%s\n\n" "Saving archive to $HASH.tar.gz" >expected &&
67 + test_cmp expected actual
68 + '
69 +
70 + # TODO(mappum)
71 + test_expect_failure "gzipped tar archive output is valid" '
72 + tar -zxf "$HASH".tar.gz &&
73 + test_cmp "$HASH" data &&
74 + rm "$HASH".tar.gz &&
75 + rm "$HASH"
76 + '
77 +
78 + test_expect_success "ipfs get succeeds (directory)" '
79 + mkdir -p dir &&
80 + touch dir/a &&
81 + mkdir -p dir/b &&
82 + echo "Hello, Worlds!" >dir/b/c &&
83 + HASH2=`ipfs add -r -q dir | tail -n 1` &&
84 + ipfs get "$HASH2" >actual
85 + '
86 +
87 + test_expect_success "ipfs get output looks good (directory)" '
88 + printf "%s\n\n" "Saving file(s) to $HASH2" >expected &&
89 + test_cmp expected actual
90 + '
91 +
92 + test_expect_success "ipfs get output is valid (directory)" '
93 + test_cmp dir/a "$HASH2"/a &&
94 + test_cmp dir/b/c "$HASH2"/b/c &&
95 + rm -r "$HASH2"
96 + '
97 +
98 + test_expect_success "ipfs get -a -C succeeds (directory)" '
99 + ipfs get "$HASH2" -a -C >actual
100 + '
101 +
102 + test_expect_success "ipfs get -a -C output looks good (directory)" '
103 + printf "%s\n\n" "Saving archive to $HASH2.tar.gz" >expected &&
104 + test_cmp expected actual
105 + '
106 +
107 + # TODO(mappum)
108 + test_expect_failure "gzipped tar archive output is valid (directory)" '
109 + tar -zxf "$HASH2".tar.gz &&
110 + test_cmp dir/a "$HASH2"/a &&
111 + test_cmp dir/b/c "$HASH2"/b/c &&
112 + rm -r "$HASH2"
113 + '
114 +}
115 +
116 +# should work offline
117 +test_get_cmd
118 +
119 +# should work online
120 +test_launch_ipfs_daemon
121 +test_get_cmd
122 test_kill_ipfs_daemon
123
124 test_done