t0080-repo.sh 3.65 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" '
Jeromy's avatar
Jeromy committed
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" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
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" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
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
	# we expect the welcome file to show up here
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
46 47
	echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >expected2
	ipfs pin ls -type=recursive >actual2
48
	test_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
49 50 51
'

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

test_expect_success "pinning directly should fail now" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
56 57
	echo Error: pin: $HASH already pinned recursively >expected3
	ipfs pin add $HASH 2>actual3
Jeromy's avatar
Jeromy committed
58
	test_cmp expected3 actual3
Jeromy's avatar
Jeromy committed
59 60
'

61
test_expect_success "'ipfs pin rm <hash>' should fail" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
62 63
	echo Error: $HASH is pinned recursively >expected4
	ipfs pin rm $HASH 2>actual4
Jeromy's avatar
Jeromy committed
64
	test_cmp expected4 actual4
65 66
'

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

test_expect_success "remove direct pin" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
75 76
	echo unpinned $HASH >expected6
	ipfs pin rm $HASH >actual6
Jeromy's avatar
Jeromy committed
77
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
78 79
'

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

test_expect_success "'ipfs refs local' no longer shows file" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
87 88 89
	echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >expected8
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>expected8
	ipfs refs local >actual8
90
	test_cmp expected8 actual8
91 92
'

Jeromy's avatar
Jeromy committed
93
test_expect_success "adding multiblock random file succeeds" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
94
	random 1000000 >multiblock
Jeromy's avatar
Jeromy committed
95 96 97 98
	MBLOCKHASH=`ipfs add -q multiblock`
'

test_expect_success "'ipfs pin ls -type=indirect' is correct" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
99 100
	ipfs refs $MBLOCKHASH | sort >refsout
	ipfs pin ls -type=indirect | sort >indirectpins
Jeromy's avatar
Jeromy committed
101 102 103 104
	test_cmp refsout indirectpins
'

test_expect_success "pin something directly" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
105
	echo "ipfs is so awesome" >awesome
Jeromy's avatar
Jeromy committed
106
	DIRECTPIN=`ipfs add -q awesome`
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
107 108
	echo unpinned $DIRECTPIN >expected9
	ipfs pin rm -r $DIRECTPIN >actual9
Jeromy's avatar
Jeromy committed
109 110
	test_cmp expected9 actual9

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
111 112
	echo pinned $DIRECTPIN directly >expected10
	ipfs pin add $DIRECTPIN >actual10
Jeromy's avatar
Jeromy committed
113 114 115 116
	test_cmp expected10 actual10
'

test_expect_success "'ipfs pin ls -type=direct' is correct" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
117 118 119 120
	echo $DIRECTPIN >directpinexpected
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>directpinexpected
	cat directpinexpected | sort >dp_exp_sorted
	ipfs pin ls -type=direct | sort >directpinout
121
	test_cmp dp_exp_sorted directpinout
Jeromy's avatar
Jeromy committed
122 123 124
'

test_expect_success "'ipfs pin ls -type=recursive' is correct" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
125 126 127 128
	echo $MBLOCKHASH >rp_expected
	echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >>rp_expected
	cat rp_expected | sort >rp_exp_sorted
	ipfs pin ls -type=recursive | sort >rp_actual
129
	test_cmp rp_exp_sorted rp_actual
Jeromy's avatar
Jeromy committed
130 131 132
'

test_expect_success "'ipfs pin ls -type=all' is correct" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
133 134 135 136 137
	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
138 139
	test_cmp allpins_sorted actual_allpins
'
Jeromy's avatar
Jeromy committed
140 141 142 143

test_kill_ipfs_daemon

test_done