test/sharness: Added tests for get
Matt Bell committed
Jan 24, 2015 at 07:07 UTC
76534bd2792704eea05e81e811bdbdb6174dc6dc
1 file changed
+118
test/sharness/t0090-get.sh
new
+118
@@ -0,0 +1,118 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2015 Matt Bell
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test get command"
8
+
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
+ 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
+ echo "Saving file(s) to $HASH
31
+" > expected &&
32
+ test_cmp expected actual
33
+'
34
+
35
+test_expect_success "ipfs get file output looks good" '
36
+ test_cmp $HASH data
37
+'
38
+
39
+test_expect_success "ipfs get errors when trying to overwrite a file" '
40
+ test_must_fail ipfs get $HASH > actual &&
41
+ rm $HASH
42
+'
43
+
44
+test_expect_success "ipfs get -a succeeds" '
45
+ ipfs get $HASH -a > actual
46
+'
47
+
48
+test_expect_success "ipfs get -a output looks good" '
49
+ echo "Saving archive to $HASH.tar
50
+" > 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
+ echo "Saving archive to $HASH.tar.gz
67
+" > expected &&
68
+ test_cmp expected actual
69
+'
70
+
71
+test_expect_success "gzipped tar archive output is valid" '
72
+ tar -xf "$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 dir &&
80
+ touch dir/a &&
81
+ mkdir 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
+ echo "Saving file(s) to $HASH2
89
+" > expected &&
90
+ test_cmp expected actual
91
+'
92
+
93
+test_expect_success "ipfs get output is valid (directory)" '
94
+ test_cmp dir/a "$HASH2"/a &&
95
+ test_cmp dir/b/c "$HASH2"/b/c &&
96
+ rm -r $HASH2
97
+'
98
+
99
+test_expect_success "ipfs get -a -C succeeds (directory)" '
100
+ ipfs get $HASH2 -a -C > actual
101
+'
102
+
103
+test_expect_success "ipfs get -a -C output looks good (directory)" '
104
+ echo "Saving archive to "$HASH2".tar.gz
105
+" > expected &&
106
+ test_cmp expected actual
107
+'
108
+
109
+test_expect_success "gzipped tar archive output is valid (directory)" '
110
+ tar -xf "$HASH2".tar.gz &&
111
+ test_cmp dir/a "$HASH2"/a &&
112
+ test_cmp dir/b/c "$HASH2"/b/c &&
113
+ rm -r $HASH2
114
+'
115
+
116
+test_kill_ipfs_daemon
117
+
118
+test_done