t0080-repo.sh 4.79 KB
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/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

test_expect_success "'ipfs add afile' succeeds" '
15
	echo "some text" >afile &&
16
	HASH=`ipfs add -q afile`
Jeromy's avatar
Jeromy committed
17 18 19
'

test_expect_success "added file was pinned" '
Etienne Laurin's avatar
Etienne Laurin committed
20
	ipfs pin ls --type=recursive >actual &&
21
	grep "$HASH" actual
Jeromy's avatar
Jeromy committed
22 23
'

24
test_expect_success "'ipfs repo gc' succeeds" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
25
	ipfs repo gc >gc_out_actual
26 27 28
'

test_expect_success "'ipfs repo gc' looks good (empty)" '
29
	true >empty &&
Jeromy's avatar
Jeromy committed
30
	test_cmp empty gc_out_actual
31 32 33
'

test_expect_success "'ipfs repo gc' doesnt remove file" '
34
	ipfs cat "$HASH" >out &&
35 36
	test_cmp out afile
'
Jeromy's avatar
Jeromy committed
37 38

test_expect_success "'ipfs pin rm' succeeds" '
39 40 41 42
	ipfs pin rm -r "$HASH" >actual1
'

test_expect_success "'ipfs pin rm' output looks good" '
43
	echo "unpinned $HASH" >expected1 &&
Jeromy's avatar
Jeromy committed
44
	test_cmp expected1 actual1
Jeromy's avatar
Jeromy committed
45 46
'

rht's avatar
rht committed
47 48 49 50 51 52 53 54 55 56
test_expect_failure "ipfs repo gc fully reverse ipfs add" '
    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
57
test_expect_success "file no longer pinned" '
58
	# we expect the welcome files and gw assets to show up here
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
59 60
	echo "$HASH_WELCOME_DOCS" >expected2 &&
	ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
61 62
	echo "$HASH_GATEWAY_ASSETS" >>expected2 &&
	ipfs refs -r "$HASH_GATEWAY_ASSETS" >>expected2 &&
Jeromy's avatar
Jeromy committed
63
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected2 &&
64
	ipfs pin ls --type=recursive --quiet >actual2 &&
Christian Couder's avatar
Christian Couder committed
65
	test_sort_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
66 67 68
'

test_expect_success "recursively pin afile" '
69
	HASH=`ipfs add -q afile` &&
70
	ipfs pin add -r "$HASH"
Jeromy's avatar
Jeromy committed
71 72 73
'

test_expect_success "pinning directly should fail now" '
74
	echo "Error: pin: $HASH already pinned recursively" >expected3 &&
75
	test_must_fail ipfs pin add "$HASH" 2>actual3 &&
Jeromy's avatar
Jeromy committed
76
	test_cmp expected3 actual3
Jeromy's avatar
Jeromy committed
77 78
'

79
test_expect_success "'ipfs pin rm <hash>' should fail" '
80
	echo "Error: $HASH is pinned recursively" >expected4 &&
81
	test_must_fail ipfs pin rm "$HASH" 2>actual4 &&
Jeromy's avatar
Jeromy committed
82
	test_cmp expected4 actual4
83 84
'

Jeromy's avatar
Jeromy committed
85
test_expect_success "remove recursive pin, add direct" '
86 87 88
	echo "unpinned $HASH" >expected5 &&
	ipfs pin rm -r "$HASH" >actual5 &&
	test_cmp expected5 actual5 &&
89
	ipfs pin add "$HASH"
Jeromy's avatar
Jeromy committed
90 91 92
'

test_expect_success "remove direct pin" '
93 94
	echo "unpinned $HASH" >expected6 &&
	ipfs pin rm "$HASH" >actual6 &&
Jeromy's avatar
Jeromy committed
95
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
96 97
'

98
test_expect_success "'ipfs repo gc' removes file" '
99 100
	echo "removed $HASH" >expected7 &&
	ipfs repo gc >actual7 &&
101 102 103
	test_cmp expected7 actual7
'

104 105
# TODO: there seems to be a serious bug with leveldb not returning a key.
test_expect_failure "'ipfs refs local' no longer shows file" '
106
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >expected8 &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
107 108
	echo "$HASH_WELCOME_DOCS" >>expected8 &&
	ipfs refs -r "$HASH_WELCOME_DOCS" >>expected8 &&
109
	ipfs refs local >actual8 &&
Christian Couder's avatar
Christian Couder committed
110
	test_sort_cmp expected8 actual8
111 112
'

Jeromy's avatar
Jeromy committed
113
test_expect_success "adding multiblock random file succeeds" '
114
	random 1000000 >multiblock &&
Jeromy's avatar
Jeromy committed
115 116 117
	MBLOCKHASH=`ipfs add -q multiblock`
'

Etienne Laurin's avatar
Etienne Laurin committed
118
test_expect_success "'ipfs pin ls --type=indirect' is correct" '
119
	ipfs refs "$MBLOCKHASH" >refsout &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
120
	ipfs refs -r "$HASH_WELCOME_DOCS" >>refsout &&
121
	ipfs refs -r "$HASH_GATEWAY_ASSETS" >>refsout &&
122
	sed -i="" "s/\(.*\)/\1 indirect/g" refsout &&
Etienne Laurin's avatar
Etienne Laurin committed
123
	ipfs pin ls --type=indirect >indirectpins &&
Christian Couder's avatar
Christian Couder committed
124
	test_sort_cmp refsout indirectpins
Jeromy's avatar
Jeromy committed
125 126 127
'

test_expect_success "pin something directly" '
128 129 130 131 132 133 134 135
	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 &&
	ipfs pin add "$DIRECTPIN" >actual10 &&
Jeromy's avatar
Jeromy committed
136 137 138
	test_cmp expected10 actual10
'

Etienne Laurin's avatar
Etienne Laurin committed
139
test_expect_success "'ipfs pin ls --type=direct' is correct" '
140
	echo "$DIRECTPIN direct" >directpinexpected &&
Etienne Laurin's avatar
Etienne Laurin committed
141
	ipfs pin ls --type=direct >directpinout &&
Christian Couder's avatar
Christian Couder committed
142
	test_sort_cmp directpinexpected directpinout
Jeromy's avatar
Jeromy committed
143 144
'

Etienne Laurin's avatar
Etienne Laurin committed
145
test_expect_success "'ipfs pin ls --type=recursive' is correct" '
146
	echo "$MBLOCKHASH" >rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
147
	echo "$HASH_WELCOME_DOCS" >>rp_expected &&
148
	echo "$HASH_GATEWAY_ASSETS" >>rp_expected &&
Jeromy's avatar
Jeromy committed
149
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
150
	ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
151
	ipfs refs -r "$HASH_GATEWAY_ASSETS" >>rp_expected &&
152
	sed -i="" "s/\(.*\)/\1 recursive/g" rp_expected &&
Etienne Laurin's avatar
Etienne Laurin committed
153
	ipfs pin ls --type=recursive >rp_actual &&
Christian Couder's avatar
Christian Couder committed
154
	test_sort_cmp rp_expected rp_actual
Jeromy's avatar
Jeromy committed
155 156
'

157
test_expect_success "'ipfs pin ls --type=all --quiet' is correct" '
158 159 160
	cat directpinout >allpins &&
	cat rp_actual >>allpins &&
	cat indirectpins >>allpins &&
161 162 163
	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
164
'
Jeromy's avatar
Jeromy committed
165 166 167 168

test_kill_ipfs_daemon

test_done