t0080-repo.sh 4.77 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
	ipfs pin add -r "$HASH"
Jeromy's avatar
Jeromy committed
70 71 72
'

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

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

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

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

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

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

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

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

test_expect_success "pin something directly" '
127 128 129 130 131 132 133 134
	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
135 136 137
	test_cmp expected10 actual10
'

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

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

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

test_kill_ipfs_daemon

test_done