t0080-repo.sh 4.06 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
	ipfs pin ls -type=recursive >actual2 &&
Christian Couder's avatar
Christian Couder committed
53
	test_sort_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
54 55 56
'

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

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

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

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

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

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

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

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

test_expect_success "'ipfs pin ls -type=indirect' is correct" '
106
	ipfs refs "$MBLOCKHASH" >refsout &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
107
	ipfs refs -r "$HASH_WELCOME_DOCS" >>refsout &&
108
	ipfs pin ls -type=indirect >indirectpins &&
Christian Couder's avatar
Christian Couder committed
109
	test_sort_cmp refsout indirectpins
Jeromy's avatar
Jeromy committed
110 111 112
'

test_expect_success "pin something directly" '
113 114 115 116 117 118 119 120
	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
121 122 123 124
	test_cmp expected10 actual10
'

test_expect_success "'ipfs pin ls -type=direct' is correct" '
125
	echo "$DIRECTPIN" >directpinexpected &&
126
	ipfs pin ls -type=direct >directpinout &&
Christian Couder's avatar
Christian Couder committed
127
	test_sort_cmp directpinexpected directpinout
Jeromy's avatar
Jeromy committed
128 129 130
'

test_expect_success "'ipfs pin ls -type=recursive' is correct" '
131
	echo "$MBLOCKHASH" >rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
132
	echo "$HASH_WELCOME_DOCS" >>rp_expected &&
Jeromy's avatar
Jeromy committed
133
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>rp_expected &&
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
134
	ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
135
	ipfs pin ls -type=recursive >rp_actual &&
Christian Couder's avatar
Christian Couder committed
136
	test_sort_cmp rp_expected rp_actual
Jeromy's avatar
Jeromy committed
137 138 139
'

test_expect_success "'ipfs pin ls -type=all' is correct" '
140 141 142
	cat directpinout >allpins &&
	cat rp_actual >>allpins &&
	cat indirectpins >>allpins &&
Jeromy's avatar
Jeromy committed
143
	cat allpins | sort | uniq >> allpins_uniq &&
144
	ipfs pin ls -type=all >actual_allpins &&
Jeromy's avatar
Jeromy committed
145
	test_sort_cmp allpins_uniq actual_allpins
Jeromy's avatar
Jeromy committed
146
'
Jeromy's avatar
Jeromy committed
147 148 149 150

test_kill_ipfs_daemon

test_done