t0080-repo.sh 1.97 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 21 22 23
#!/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" '
	ipfs pin ls -type=recursive | grep `cat hashfile`
'

24 25 26 27 28
test_expect_success "'ipfs repo gc' doesnt remove file" '
	ipfs repo gc
	ipfs cat `cat hashfile` > out
	test_cmp out afile
'
Jeromy's avatar
Jeromy committed
29 30

test_expect_success "'ipfs pin rm' succeeds" '
Jeromy's avatar
Jeromy committed
31 32 33
	echo unpinned `cat hashfile` > expected1
	ipfs pin rm -r `cat hashfile` > actual1
	test_cmp expected1 actual1
Jeromy's avatar
Jeromy committed
34 35 36
'

test_expect_success "file no longer pinned" '
Jeromy's avatar
Jeromy committed
37 38 39
	echo -n "" > expected2
	ipfs pin ls -type=recursive > actual2
	test_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
40 41 42 43 44 45 46
'

test_expect_success "recursively pin afile" '
	ipfs pin add -r `cat hashfile`
'

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

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

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

test_expect_success "remove direct pin" '
Jeromy's avatar
Jeromy committed
66 67 68
	echo unpinned `cat hashfile` > expected6
	ipfs pin rm `cat hashfile` > actual6
	test_cmp expected6 actual6
Jeromy's avatar
Jeromy committed
69 70
'

71 72 73 74 75 76 77 78 79 80 81 82
test_expect_success "'ipfs repo gc' removes file" '
	echo removed `cat hashfile` > expected7
	ipfs repo gc > actual7
	test_cmp expected7 actual7
'

test_expect_success "'ipfs refs local' no longer shows file" '
	echo -n "" > expected8
	ipfs refs local > actual8
	test_cmp expected8 actual8
'

Jeromy's avatar
Jeromy committed
83 84 85 86

test_kill_ipfs_daemon

test_done