t0080-repo.sh 1.62 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 24 25 26
#!/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`
'

# TODO: run gc, then ipfs cat file, should still be there

test_expect_success "'ipfs pin rm' succeeds" '
Jeromy's avatar
Jeromy committed
27 28 29
	echo unpinned `cat hashfile` > expected1
	ipfs pin rm -r `cat hashfile` > actual1
	test_cmp expected1 actual1
Jeromy's avatar
Jeromy committed
30 31 32
'

test_expect_success "file no longer pinned" '
Jeromy's avatar
Jeromy committed
33 34 35
	echo -n "" > expected2
	ipfs pin ls -type=recursive > actual2
	test_cmp expected2 actual2
Jeromy's avatar
Jeromy committed
36 37 38 39 40 41 42
'

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
43 44 45
	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
46 47
'

48
test_expect_success "'ipfs pin rm <hash>' should fail" '
Jeromy's avatar
Jeromy committed
49 50 51
	echo Error: `cat hashfile` is pinned recursively > expected4
	ipfs pin rm `cat hashfile` 2> actual4
	test_cmp expected4 actual4
52 53
'

Jeromy's avatar
Jeromy committed
54
test_expect_success "remove recursive pin, add direct" '
Jeromy's avatar
Jeromy committed
55 56 57
	echo unpinned `cat hashfile` > expected5
	ipfs pin rm -r `cat hashfile` > actual5
	test_cmp expected5 actual5
Jeromy's avatar
Jeromy committed
58 59 60 61
	ipfs pin add `cat hashfile`
'

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


test_kill_ipfs_daemon

test_done