t0080-repo.sh 3.09 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' doesnt remove file" '
Jeromy's avatar
Jeromy committed
25 26 27 28
	echo -n "" > empty
	ipfs repo gc > gc_out_actual
	test_cmp empty gc_out_actual
	ipfs cat $HASH > out
29 30
	test_cmp out afile
'
Jeromy's avatar
Jeromy committed
31 32

test_expect_success "'ipfs pin rm' succeeds" '
Jeromy's avatar
Jeromy committed
33 34
	echo unpinned $HASH > expected1
	ipfs pin rm -r $HASH > actual1
Jeromy's avatar
Jeromy committed
35
	test_cmp expected1 actual1
Jeromy's avatar
Jeromy committed
36 37 38
'

test_expect_success "file no longer pinned" '
Jeromy's avatar
Jeromy committed
39
	ipfs pin ls -type=recursive > actual2
Jeromy's avatar
Jeromy committed
40
	test_cmp empty actual2
Jeromy's avatar
Jeromy committed
41 42 43
'

test_expect_success "recursively pin afile" '
Jeromy's avatar
Jeromy committed
44
	ipfs pin add -r $HASH
Jeromy's avatar
Jeromy committed
45 46 47
'

test_expect_success "pinning directly should fail now" '
Jeromy's avatar
Jeromy committed
48 49
	echo Error: pin: $HASH already pinned recursively > expected3
	ipfs pin add $HASH 2> actual3
Jeromy's avatar
Jeromy committed
50
	test_cmp expected3 actual3
Jeromy's avatar
Jeromy committed
51 52
'

53
test_expect_success "'ipfs pin rm <hash>' should fail" '
Jeromy's avatar
Jeromy committed
54 55
	echo Error: $HASH is pinned recursively > expected4
	ipfs pin rm $HASH 2> actual4
Jeromy's avatar
Jeromy committed
56
	test_cmp expected4 actual4
57 58
'

Jeromy's avatar
Jeromy committed
59
test_expect_success "remove recursive pin, add direct" '
Jeromy's avatar
Jeromy committed
60 61
	echo unpinned $HASH > expected5
	ipfs pin rm -r $HASH > actual5
Jeromy's avatar
Jeromy committed
62
	test_cmp expected5 actual5
Jeromy's avatar
Jeromy committed
63
	ipfs pin add $HASH
Jeromy's avatar
Jeromy committed
64 65 66
'

test_expect_success "remove direct pin" '
Jeromy's avatar
Jeromy committed
67 68
	echo unpinned $HASH > expected6
	ipfs pin rm $HASH > actual6
Jeromy's avatar
Jeromy committed
69
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
70 71
'

72
test_expect_success "'ipfs repo gc' removes file" '
Jeromy's avatar
Jeromy committed
73
	echo removed $HASH > expected7
74 75 76 77 78 79
	ipfs repo gc > actual7
	test_cmp expected7 actual7
'

test_expect_success "'ipfs refs local' no longer shows file" '
	ipfs refs local > actual8
Jeromy's avatar
Jeromy committed
80
	test_cmp empty actual8
81 82
'

Jeromy's avatar
Jeromy committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
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" '
	echo $DIRECTPIN > directpinhash
	ipfs pin ls -type=direct > directpinout
	test_cmp directpinhash directpinout
'

test_expect_success "'ipfs pin ls -type=recursive' is correct" '
	echo $MBLOCKHASH > rp_expected
	ipfs pin ls -type=recursive > rp_actual
	test_cmp rp_expected rp_actual
'

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
126 127 128 129

test_kill_ipfs_daemon

test_done