t0080-repo.sh 4.12 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" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
15
	echo "some text" >afile
Jeromy's avatar
Jeromy committed
16
	HASH=`ipfs add -q afile`
17
	printf "$HASH" >hashfile
Jeromy's avatar
Jeromy committed
18 19 20
'

test_expect_success "added file was pinned" '
21
	ipfs pin ls -type=recursive | grep "$HASH"
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
	printf "" >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
	echo "unpinned $HASH" >expected1
	ipfs pin rm -r "$HASH" >actual1
Jeromy's avatar
Jeromy committed
41
	test_cmp expected1 actual1
Jeromy's avatar
Jeromy committed
42 43 44
'

test_expect_success "file no longer pinned" '
45 46 47 48 49 50
	# we expect the welcome files to show up here
	echo QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >expected2
	ipfs refs -r QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>expected2
	cat expected2 | sort >expected_sorted2
	ipfs pin ls -type=recursive | sort >actual2
	test_cmp expected_sorted2 actual2
Jeromy's avatar
Jeromy committed
51 52 53
'

test_expect_success "recursively pin afile" '
54
	ipfs pin add -r "$HASH"
Jeromy's avatar
Jeromy committed
55 56 57
'

test_expect_success "pinning directly should fail now" '
58 59
	echo "Error: pin: $HASH already pinned recursively" >expected3
	ipfs pin add "$HASH" 2>actual3
Jeromy's avatar
Jeromy committed
60
	test_cmp expected3 actual3
Jeromy's avatar
Jeromy committed
61 62
'

63
test_expect_success "'ipfs pin rm <hash>' should fail" '
64 65
	echo "Error: $HASH is pinned recursively" >expected4
	ipfs pin rm "$HASH" 2>actual4
Jeromy's avatar
Jeromy committed
66
	test_cmp expected4 actual4
67 68
'

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

test_expect_success "remove direct pin" '
77 78
	echo "unpinned $HASH" >expected6
	ipfs pin rm "$HASH" >actual6
Jeromy's avatar
Jeromy committed
79
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
80 81
'

82
test_expect_success "'ipfs repo gc' removes file" '
83
	echo "removed $HASH" >expected7
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
84
	ipfs repo gc >actual7
85 86 87 88
	test_cmp expected7 actual7
'

test_expect_success "'ipfs refs local' no longer shows file" '
89 90 91 92 93 94
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >expected8
	echo QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>expected8
	ipfs refs -r QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>expected8
	cat expected8 | sort >expected_sorted8
	ipfs refs local | sort >actual8
	test_cmp expected_sorted8 actual8
95 96
'

Jeromy's avatar
Jeromy committed
97
test_expect_success "adding multiblock random file succeeds" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
98
	random 1000000 >multiblock
Jeromy's avatar
Jeromy committed
99 100 101 102
	MBLOCKHASH=`ipfs add -q multiblock`
'

test_expect_success "'ipfs pin ls -type=indirect' is correct" '
103 104 105
	ipfs refs "$MBLOCKHASH" >refsout
	ipfs refs -r "QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT" >>refsout
	cat refsout | sort >refsout_sorted
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
106
	ipfs pin ls -type=indirect | sort >indirectpins
107
	test_cmp refsout_sorted indirectpins
Jeromy's avatar
Jeromy committed
108 109 110
'

test_expect_success "pin something directly" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
111
	echo "ipfs is so awesome" >awesome
Jeromy's avatar
Jeromy committed
112
	DIRECTPIN=`ipfs add -q awesome`
113 114
	echo "unpinned $DIRECTPIN" >expected9
	ipfs pin rm -r "$DIRECTPIN" >actual9
Jeromy's avatar
Jeromy committed
115 116
	test_cmp expected9 actual9

117 118
	echo "pinned $DIRECTPIN directly" >expected10
	ipfs pin add "$DIRECTPIN" >actual10
Jeromy's avatar
Jeromy committed
119 120 121 122
	test_cmp expected10 actual10
'

test_expect_success "'ipfs pin ls -type=direct' is correct" '
123
	echo "$DIRECTPIN" >directpinexpected
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
124 125 126
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>directpinexpected
	cat directpinexpected | sort >dp_exp_sorted
	ipfs pin ls -type=direct | sort >directpinout
127
	test_cmp dp_exp_sorted directpinout
Jeromy's avatar
Jeromy committed
128 129 130
'

test_expect_success "'ipfs pin ls -type=recursive' is correct" '
131
	echo "$MBLOCKHASH" >rp_expected
132 133
	echo QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT >>rp_expected
	ipfs refs -r "QmPXME1oRtoT627YKaDPDQ3PwA8tdP9rWuAAweLzqSwAWT" >>rp_expected
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
134 135
	cat rp_expected | sort >rp_exp_sorted
	ipfs pin ls -type=recursive | sort >rp_actual
136
	test_cmp rp_exp_sorted rp_actual
Jeromy's avatar
Jeromy committed
137 138 139
'

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

test_kill_ipfs_daemon

test_done