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" '
20 21
	ipfs pin ls -type=recursive >actual &&
	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 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 &&
Jeromy's avatar
Jeromy committed
51
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected2 &&
52 53 54 55
	sort expected2 >expected_sorted2 &&
	ipfs pin ls -type=recursive >actual2 &&
	sort actual2 >actual_sorted2 &&
	test_cmp expected_sorted2 actual_sorted2
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 99 100 101
	sort expected8 >expected_sorted8 &&
	ipfs refs local >actual8 &&
	sort actual8 >actual_sorted8 &&
	test_cmp expected_sorted8 actual_sorted8
102 103
'

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

test_expect_success "'ipfs pin ls -type=indirect' is correct" '
110
	ipfs refs "$MBLOCKHASH" >refsout &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
111
	ipfs refs -r "$HASH_WELCOME_DOCS" >>refsout &&
112 113 114 115
	sort refsout >refsout_sorted &&
	ipfs pin ls -type=indirect >indirectpins &&
	sort indirectpins >indirectpins_sorted &&
	test_cmp refsout_sorted indirectpins_sorted
Jeromy's avatar
Jeromy committed
116 117 118
'

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

test_expect_success "'ipfs pin ls -type=direct' is correct" '
131
	echo "$DIRECTPIN" >directpinexpected &&
132 133 134 135
	sort directpinexpected >dp_exp_sorted &&
	ipfs pin ls -type=direct >directpinout &&
	sort directpinout >dp_out_sorted &&
	test_cmp dp_exp_sorted dp_out_sorted
Jeromy's avatar
Jeromy committed
136 137 138
'

test_expect_success "'ipfs pin ls -type=recursive' is correct" '
139
	echo "$MBLOCKHASH" >rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
140
	echo "$HASH_WELCOME_DOCS" >>rp_expected &&
Jeromy's avatar
Jeromy committed
141
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
142
	ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
143 144 145 146
	sort rp_expected >rp_exp_sorted &&
	ipfs pin ls -type=recursive >rp_actual &&
	sort rp_actual >rp_act_sorted &&
	test_cmp rp_exp_sorted rp_act_sorted
Jeromy's avatar
Jeromy committed
147 148 149
'

test_expect_success "'ipfs pin ls -type=all' is correct" '
150 151 152
	cat directpinout >allpins &&
	cat rp_actual >>allpins &&
	cat indirectpins >>allpins &&
153 154 155 156
	sort allpins >allpins_sorted &&
	ipfs pin ls -type=all >actual_allpins &&
	sort actual_allpins >actual_allpins_sorted &&
	test_cmp allpins_sorted actual_allpins_sorted
Jeromy's avatar
Jeromy committed
157
'
Jeromy's avatar
Jeromy committed
158 159 160 161

test_kill_ipfs_daemon

test_done