t0080-repo.sh 3.69 KB
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/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" '
	echo "some text" > afile
	HASH=`ipfs add -q afile`
	echo -n $HASH > hashfile
'

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" '
Jeromy's avatar
Jeromy committed
25
	ipfs repo gc > gc_out_actual
26 27 28 29
'

test_expect_success "'ipfs repo gc' looks good (empty)" '
	echo -n "" > 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" '
Jeromy's avatar
Jeromy 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" '
Jeromy's avatar
Jeromy 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
46
	echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ > expected2
Jeromy's avatar
Jeromy committed
47
	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" '
Jeromy's avatar
Jeromy 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" '
Jeromy's avatar
Jeromy 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" '
Jeromy's avatar
Jeromy 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" '
Jeromy's avatar
Jeromy 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" '
Jeromy's avatar
Jeromy committed
81
	echo removed $HASH > expected7
82 83 84 85 86
	ipfs repo gc > actual7
	test_cmp expected7 actual7
'

test_expect_success "'ipfs refs local' no longer shows file" '
87 88
	echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ > expected8
	echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >> expected8
89
	ipfs refs local > actual8
90
	test_cmp expected8 actual8
91 92
'

Jeromy's avatar
Jeromy committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
test_expect_success "adding multiblock random file succeeds" '
	random 1000000 > multiblock
	MBLOCKHASH=`ipfs add -q multiblock`
'

test_expect_success "'ipfs pin ls -type=indirect' is correct" '
	ipfs refs $MBLOCKHASH | sort > refsout
	ipfs pin ls -type=indirect | sort > indirectpins
	test_cmp refsout indirectpins
'

test_expect_success "pin something directly" '
	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
	test_cmp expected10 actual10
'

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

test_expect_success "'ipfs pin ls -type=recursive' is correct" '
	echo $MBLOCKHASH > rp_expected
126
	echo QmTTFXiXoixwT53tcGPu419udsHEHYu6AHrQC8HAKdJYaZ >> rp_expected
127 128 129
	cat rp_expected | sort > rp_exp_sorted
	ipfs pin ls -type=recursive | sort > rp_actual
	test_cmp rp_exp_sorted rp_actual
Jeromy's avatar
Jeromy committed
130 131 132 133 134 135 136 137 138 139
'

test_expect_success "'ipfs pin ls -type=all' is correct" '
	cat directpinout > allpins
	cat rp_actual >> allpins
	cat indirectpins >> allpins
	cat allpins | sort > allpins_sorted
	ipfs pin ls -type=all | sort > actual_allpins
	test_cmp allpins_sorted actual_allpins
'
Jeromy's avatar
Jeromy committed
140 141 142 143

test_kill_ipfs_daemon

test_done