t0080-repo.sh 6.46 KB
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/sh
#
# Copyright (c) 2014 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test ipfs repo operations"

. lib/test-lib.sh

test_init_ipfs
test_launch_ipfs_daemon

14 15 16 17 18 19 20 21 22
test_expect_success "'ipfs repo gc' succeeds" '
	ipfs repo gc >gc_out_actual
'

test_expect_success "'ipfs repo gc' looks good (empty)" '
	true >empty &&
	test_cmp empty gc_out_actual
'

Jeromy's avatar
Jeromy committed
23
test_expect_success "'ipfs add afile' succeeds" '
24
	echo "some text" >afile &&
25
	HASH=`ipfs add -q afile`
Jeromy's avatar
Jeromy committed
26 27 28
'

test_expect_success "added file was pinned" '
Etienne Laurin's avatar
Etienne Laurin committed
29
	ipfs pin ls --type=recursive >actual &&
30
	grep "$HASH" actual
Jeromy's avatar
Jeromy committed
31 32
'

33
test_expect_success "'ipfs repo gc' succeeds" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34
	ipfs repo gc >gc_out_actual
35 36
'

37 38 39 40
test_expect_success "'ipfs repo gc' looks good (patch root)" '
	PATCH_ROOT=QmQXirSbubiySKnqaFyfs5YzziXRB5JEVQVjU6xsd7innr &&
	echo "removed $PATCH_ROOT" >patch_root &&
	test_cmp patch_root gc_out_actual
41 42 43
'

test_expect_success "'ipfs repo gc' doesnt remove file" '
44
	ipfs cat "$HASH" >out &&
45 46
	test_cmp out afile
'
Jeromy's avatar
Jeromy committed
47 48

test_expect_success "'ipfs pin rm' succeeds" '
49 50 51 52
	ipfs pin rm -r "$HASH" >actual1
'

test_expect_success "'ipfs pin rm' output looks good" '
53
	echo "unpinned $HASH" >expected1 &&
Jeromy's avatar
Jeromy committed
54
	test_cmp expected1 actual1
Jeromy's avatar
Jeromy committed
55 56
'

rht's avatar
rht committed
57
test_expect_failure "ipfs repo gc fully reverse ipfs add" '
rht's avatar
rht committed
58
    ipfs repo gc &&
rht's avatar
rht committed
59 60 61 62 63 64 65 66 67
    random 100000 41 >gcfile &&
    disk_usage "$IPFS_PATH/blocks" >expected &&
    hash=`ipfs add -q gcfile` &&
    ipfs pin rm -r $hash &&
    ipfs repo gc &&
    disk_usage "$IPFS_PATH/blocks" >actual &&
    test_cmp expected actual
'

Jeromy's avatar
Jeromy committed
68
test_expect_success "file no longer pinned" '
rht's avatar
rht committed
69
	# we expect the welcome files to show up here
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
70 71
	echo "$HASH_WELCOME_DOCS" >expected2 &&
	ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
72 73
	EMPTY_DIR=QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn &&
	echo "$EMPTY_DIR" >>expected2 &&
74
	ipfs pin ls --type=recursive --quiet >actual2 &&
Christian Couder's avatar
Christian Couder committed
75
	test_sort_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
76 77
'

78
test_expect_success "recursively pin afile(default action)" '
79
	HASH=`ipfs add -q afile` &&
80 81 82 83 84 85 86 87
	ipfs pin add "$HASH"
'

test_expect_success "recursively pin rm afile (default action)" '
	ipfs pin rm "$HASH"
'

test_expect_success "recursively pin afile" '
88
	ipfs pin add -r "$HASH"
Jeromy's avatar
Jeromy committed
89 90 91
'

test_expect_success "pinning directly should fail now" '
92
	echo "Error: pin: $HASH already pinned recursively" >expected3 &&
93
	test_must_fail ipfs pin add -r=false "$HASH" 2>actual3 &&
Jeromy's avatar
Jeromy committed
94
	test_cmp expected3 actual3
Jeromy's avatar
Jeromy committed
95 96
'

97
test_expect_success "'ipfs pin rm -r=false <hash>' should fail" '
98
	echo "Error: $HASH is pinned recursively" >expected4 &&
99
	test_must_fail ipfs pin rm -r=false "$HASH" 2>actual4 &&
Jeromy's avatar
Jeromy committed
100
	test_cmp expected4 actual4
101 102
'

Jeromy's avatar
Jeromy committed
103
test_expect_success "remove recursive pin, add direct" '
104 105 106
	echo "unpinned $HASH" >expected5 &&
	ipfs pin rm -r "$HASH" >actual5 &&
	test_cmp expected5 actual5 &&
107
	ipfs pin add -r=false "$HASH"
Jeromy's avatar
Jeromy committed
108 109 110
'

test_expect_success "remove direct pin" '
111 112
	echo "unpinned $HASH" >expected6 &&
	ipfs pin rm "$HASH" >actual6 &&
Jeromy's avatar
Jeromy committed
113
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
114 115
'

116
test_expect_success "'ipfs repo gc' removes file" '
117 118
	echo "removed $PATCH_ROOT" >expected7 &&
	echo "removed $HASH" >>expected7 &&
119
	ipfs repo gc >actual7 &&
120
	test_sort_cmp expected7 actual7
121 122
'

123 124
# TODO: there seems to be a serious bug with leveldb not returning a key.
test_expect_failure "'ipfs refs local' no longer shows file" '
125 126
	EMPTY_DIR=QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn &&
	echo "$EMPTY_DIR" >expected8 &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
127 128
	echo "$HASH_WELCOME_DOCS" >>expected8 &&
	ipfs refs -r "$HASH_WELCOME_DOCS" >>expected8 &&
129
	ipfs refs local >actual8 &&
Christian Couder's avatar
Christian Couder committed
130
	test_sort_cmp expected8 actual8
131 132
'

Jeromy's avatar
Jeromy committed
133
test_expect_success "adding multiblock random file succeeds" '
134
	random 1000000 >multiblock &&
Jeromy's avatar
Jeromy committed
135 136 137
	MBLOCKHASH=`ipfs add -q multiblock`
'

Etienne Laurin's avatar
Etienne Laurin committed
138
test_expect_success "'ipfs pin ls --type=indirect' is correct" '
139
	ipfs refs "$MBLOCKHASH" >refsout &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
140
	ipfs refs -r "$HASH_WELCOME_DOCS" >>refsout &&
141
	sed -i="" "s/\(.*\)/\1 indirect/g" refsout &&
Etienne Laurin's avatar
Etienne Laurin committed
142
	ipfs pin ls --type=indirect >indirectpins &&
Christian Couder's avatar
Christian Couder committed
143
	test_sort_cmp refsout indirectpins
Jeromy's avatar
Jeromy committed
144 145 146
'

test_expect_success "pin something directly" '
147 148 149 150 151 152 153
	echo "ipfs is so awesome" >awesome &&
	DIRECTPIN=`ipfs add -q awesome` &&
	echo "unpinned $DIRECTPIN" >expected9 &&
	ipfs pin rm -r "$DIRECTPIN" >actual9 &&
	test_cmp expected9 actual9  &&

	echo "pinned $DIRECTPIN directly" >expected10 &&
154
	ipfs pin add -r=false "$DIRECTPIN" >actual10 &&
Jeromy's avatar
Jeromy committed
155 156 157
	test_cmp expected10 actual10
'

Etienne Laurin's avatar
Etienne Laurin committed
158
test_expect_success "'ipfs pin ls --type=direct' is correct" '
159
	echo "$DIRECTPIN direct" >directpinexpected &&
Etienne Laurin's avatar
Etienne Laurin committed
160
	ipfs pin ls --type=direct >directpinout &&
Christian Couder's avatar
Christian Couder committed
161
	test_sort_cmp directpinexpected directpinout
Jeromy's avatar
Jeromy committed
162 163
'

Etienne Laurin's avatar
Etienne Laurin committed
164
test_expect_success "'ipfs pin ls --type=recursive' is correct" '
165
	echo "$MBLOCKHASH" >rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
166
	echo "$HASH_WELCOME_DOCS" >>rp_expected &&
167
	echo "$EMPTY_DIR" >>rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
168
	ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
169
	sed -i="" "s/\(.*\)/\1 recursive/g" rp_expected &&
Etienne Laurin's avatar
Etienne Laurin committed
170
	ipfs pin ls --type=recursive >rp_actual &&
Christian Couder's avatar
Christian Couder committed
171
	test_sort_cmp rp_expected rp_actual
Jeromy's avatar
Jeromy committed
172 173
'

174
test_expect_success "'ipfs pin ls --type=all --quiet' is correct" '
175 176 177
	cat directpinout >allpins &&
	cat rp_actual >>allpins &&
	cat indirectpins >>allpins &&
178 179 180
	cut -f1 -d " " allpins | sort | uniq >> allpins_uniq_hashes &&
	ipfs pin ls --type=all --quiet >actual_allpins &&
	test_sort_cmp allpins_uniq_hashes actual_allpins
Jeromy's avatar
Jeromy committed
181
'
Jeromy's avatar
Jeromy committed
182

gatesvp's avatar
gatesvp committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
test_expect_success "'ipfs refs --unique' is correct" '
	mkdir -p uniques &&
	cd uniques &&
	echo "content1" > file1 &&
	echo "content1" > file2 &&
	ROOT=$(ipfs add -r -q . | tail -n1) &&
	ipfs refs --unique $ROOT >expected &&
	ipfs add -q file1 >unique_hash &&
	test_cmp expected unique_hash
'

test_expect_success "'ipfs refs --unique --recursive' is correct" '
	mkdir -p a/b/c &&
	echo "c1" > a/f1 &&
	echo "c1" > a/b/f1 &&
	echo "c1" > a/b/c/f1 &&
	echo "c2" > a/b/c/f2 &&
	ROOT=$(ipfs add -r -q a | tail -n1) &&
	ipfs refs --unique --recursive $ROOT >refs_output &&
	wc -l refs_output | sed "s/^ *//g" >line_count &&
	echo "4 refs_output" >expected &&
	test_cmp expected line_count
'

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
test_expect_success "'ipfs refs --recursive (bigger)'" '
	mkdir -p b/c/d/e &&
	echo "content1" >b/f &&
	echo "content1" >b/c/f1 &&
	echo "content1" >b/c/d/f2 &&
	echo "content2" >b/c/f2 &&
	echo "content2" >b/c/d/f1 &&
	echo "content2" >b/c/d/e/f &&
	cp -r b b2 && mv b2 b/b2 &&
	cp -r b b3 && mv b3 b/b3 &&
	cp -r b b4 && mv b4 b/b4 &&
	hash=$(ipfs add -r -q b | tail -n1) &&
	ipfs refs -r "$hash" | wc -l | sed "s/^ *//g" >actual &&
	echo "79" >expected &&
	test_cmp expected actual
'

test_expect_success "'ipfs refs --unique --recursive (bigger)'" '
	ipfs refs -r "$hash" | sort | uniq >expected &&
	ipfs refs -r -u "$hash" | sort >actual &&
	test_cmp expected actual
'

Jeromy's avatar
Jeromy committed
230 231 232
test_kill_ipfs_daemon

test_done