t0080-repo.sh 4.47 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 47
'

test_expect_success "file no longer pinned" '
48
	# we expect the welcome files and gw assets to show up here
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
49 50
	echo "$HASH_WELCOME_DOCS" >expected2 &&
	ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
51 52
	echo "$HASH_GATEWAY_ASSETS" >>expected2 &&
	ipfs refs -r "$HASH_GATEWAY_ASSETS" >>expected2 &&
Jeromy's avatar
Jeromy committed
53
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected2 &&
54
	ipfs pin ls --type=recursive --quiet >actual2 &&
Christian Couder's avatar
Christian Couder committed
55
	test_sort_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
56 57 58
'

test_expect_success "recursively pin afile" '
59
	ipfs pin add -r "$HASH"
Jeromy's avatar
Jeromy committed
60 61 62
'

test_expect_success "pinning directly should fail now" '
63
	echo "Error: pin: $HASH already pinned recursively" >expected3 &&
64
	test_must_fail ipfs pin add "$HASH" 2>actual3 &&
Jeromy's avatar
Jeromy committed
65
	test_cmp expected3 actual3
Jeromy's avatar
Jeromy committed
66 67
'

68
test_expect_success "'ipfs pin rm <hash>' should fail" '
69
	echo "Error: $HASH is pinned recursively" >expected4 &&
70
	test_must_fail ipfs pin rm "$HASH" 2>actual4 &&
Jeromy's avatar
Jeromy committed
71
	test_cmp expected4 actual4
72 73
'

Jeromy's avatar
Jeromy committed
74
test_expect_success "remove recursive pin, add direct" '
75 76 77
	echo "unpinned $HASH" >expected5 &&
	ipfs pin rm -r "$HASH" >actual5 &&
	test_cmp expected5 actual5 &&
78
	ipfs pin add "$HASH"
Jeromy's avatar
Jeromy committed
79 80 81
'

test_expect_success "remove direct pin" '
82 83
	echo "unpinned $HASH" >expected6 &&
	ipfs pin rm "$HASH" >actual6 &&
Jeromy's avatar
Jeromy committed
84
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
85 86
'

87
test_expect_success "'ipfs repo gc' removes file" '
88 89
	echo "removed $HASH" >expected7 &&
	ipfs repo gc >actual7 &&
90 91 92
	test_cmp expected7 actual7
'

93 94
# TODO: there seems to be a serious bug with leveldb not returning a key.
test_expect_failure "'ipfs refs local' no longer shows file" '
95
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >expected8 &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
96 97
	echo "$HASH_WELCOME_DOCS" >>expected8 &&
	ipfs refs -r "$HASH_WELCOME_DOCS" >>expected8 &&
98
	ipfs refs local >actual8 &&
Christian Couder's avatar
Christian Couder committed
99
	test_sort_cmp expected8 actual8
100 101
'

Jeromy's avatar
Jeromy committed
102
test_expect_success "adding multiblock random file succeeds" '
103
	random 1000000 >multiblock &&
Jeromy's avatar
Jeromy committed
104 105 106
	MBLOCKHASH=`ipfs add -q multiblock`
'

Etienne Laurin's avatar
Etienne Laurin committed
107
test_expect_success "'ipfs pin ls --type=indirect' is correct" '
108
	ipfs refs "$MBLOCKHASH" >refsout &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
109
	ipfs refs -r "$HASH_WELCOME_DOCS" >>refsout &&
110
	ipfs refs -r "$HASH_GATEWAY_ASSETS" >>refsout &&
111
	sed -i="" "s/\(.*\)/\1 indirect/g" refsout &&
Etienne Laurin's avatar
Etienne Laurin committed
112
	ipfs pin ls --type=indirect >indirectpins &&
Christian Couder's avatar
Christian Couder committed
113
	test_sort_cmp refsout indirectpins
Jeromy's avatar
Jeromy committed
114 115 116
'

test_expect_success "pin something directly" '
117 118 119 120 121 122 123 124
	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
125 126 127
	test_cmp expected10 actual10
'

Etienne Laurin's avatar
Etienne Laurin committed
128
test_expect_success "'ipfs pin ls --type=direct' is correct" '
129
	echo "$DIRECTPIN direct" >directpinexpected &&
Etienne Laurin's avatar
Etienne Laurin committed
130
	ipfs pin ls --type=direct >directpinout &&
Christian Couder's avatar
Christian Couder committed
131
	test_sort_cmp directpinexpected directpinout
Jeromy's avatar
Jeromy committed
132 133
'

Etienne Laurin's avatar
Etienne Laurin committed
134
test_expect_success "'ipfs pin ls --type=recursive' is correct" '
135
	echo "$MBLOCKHASH" >rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
136
	echo "$HASH_WELCOME_DOCS" >>rp_expected &&
137
	echo "$HASH_GATEWAY_ASSETS" >>rp_expected &&
Jeromy's avatar
Jeromy committed
138
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
139
	ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
140
	ipfs refs -r "$HASH_GATEWAY_ASSETS" >>rp_expected &&
141
	sed -i="" "s/\(.*\)/\1 recursive/g" rp_expected &&
Etienne Laurin's avatar
Etienne Laurin committed
142
	ipfs pin ls --type=recursive >rp_actual &&
Christian Couder's avatar
Christian Couder committed
143
	test_sort_cmp rp_expected rp_actual
Jeromy's avatar
Jeromy committed
144 145
'

146
test_expect_success "'ipfs pin ls --type=all --quiet' is correct" '
147 148 149
	cat directpinout >allpins &&
	cat rp_actual >>allpins &&
	cat indirectpins >>allpins &&
150 151 152
	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
153
'
Jeromy's avatar
Jeromy committed
154 155 156 157

test_kill_ipfs_daemon

test_done