t0050-block.sh 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/sh
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test block command"

. lib/test-lib.sh

11
test_init_ipfs
12 13 14 15 16 17 18 19

test_expect_success "'ipfs block put' succeeds" '
	echo "Hello Mars!" >expected_in &&
	ipfs block put <expected_in >actual_out
'

test_expect_success "'ipfs block put' output looks good" '
	HASH="QmRKqGMAM6EZngbpjSqrvYzq5Qd8b1bSWymjSUY9zQSNDk" &&
20
	echo "$HASH" >expected_out &&
21 22 23 24 25 26 27 28 29 30 31
	test_cmp expected_out actual_out
'

test_expect_success "'ipfs block get' succeeds" '
	ipfs block get $HASH >actual_in
'

test_expect_success "'ipfs block get' output looks good" '
	test_cmp expected_in actual_in
'

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
32 33 34 35
test_expect_success "'ipfs block stat' succeeds" '
  ipfs block stat $HASH >actual_stat
'

Kevin Atkinson's avatar
Kevin Atkinson committed
36
test_expect_success "'ipfs block stat' output looks good" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
37 38 39 40 41
  echo "Key: $HASH" >expected_stat &&
  echo "Size: 12" >>expected_stat &&
  test_cmp expected_stat actual_stat
'

Kevin Atkinson's avatar
Kevin Atkinson committed
42 43 44 45 46
test_expect_success "'ipfs block rm' succeeds" '
  ipfs block rm $HASH >actual_rm
'

test_expect_success "'ipfs block rm' output looks good" '
47
  echo "removed $HASH" > expected_rm &&
Kevin Atkinson's avatar
Kevin Atkinson committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  test_cmp expected_rm actual_rm
'

test_expect_success "'ipfs block rm' block actually removed" '
  test_must_fail ipfs block stat $HASH
'

DIRHASH=QmdWmVmM6W2abTgkEfpbtA1CJyTWS2rhuUB9uP1xV8Uwtf
FILE1HASH=Qmae3RedM7SNkWGsdzYzsr6svmsFdsva4WoTvYYsWhUSVz
FILE2HASH=QmUtkGLvPf63NwVzLPKPUYgwhn8ZYPWF6vKWN3fZ2amfJF
FILE3HASH=Qmesmmf1EEG1orJb6XdK6DabxexsseJnCfw8pqWgonbkoj

test_expect_success "add and pin directory" '
  mkdir adir &&
  echo "file1" > adir/file1 &&
  echo "file2" > adir/file2 &&
  echo "file3" > adir/file3 &&
  ipfs add -r adir
  ipfs pin add -r $DIRHASH
'

test_expect_success "can't remove pinned block" '
  test_must_fail ipfs block rm $DIRHASH 2> block_rm_err
'

test_expect_success "can't remove pinned block: output looks good" '
74
  grep -q "$DIRHASH: pinned: recursive" block_rm_err
Kevin Atkinson's avatar
Kevin Atkinson committed
75 76 77 78 79 80 81
'

test_expect_success "can't remove indirectly pinned block" '
  test_must_fail ipfs block rm $FILE1HASH 2> block_rm_err
'

test_expect_success "can't remove indirectly pinned block: output looks good" '
82
  grep -q "$FILE1HASH: pinned via $DIRHASH" block_rm_err
Kevin Atkinson's avatar
Kevin Atkinson committed
83 84
'

85
test_expect_success "remove pin" '
Kevin Atkinson's avatar
Kevin Atkinson committed
86 87 88 89 90 91 92 93
  ipfs pin rm -r $DIRHASH
'

test_expect_success "multi-block 'ipfs block rm' succeeds" '
  ipfs block rm $FILE1HASH $FILE2HASH $FILE3HASH > actual_rm
'

test_expect_success "multi-block 'ipfs block rm' output looks good" '
94 95 96
  grep -F -q "removed $FILE1HASH" actual_rm &&
  grep -F -q "removed $FILE2HASH" actual_rm &&
  grep -F -q "removed $FILE3HASH" actual_rm
Kevin Atkinson's avatar
Kevin Atkinson committed
97 98
'

99 100 101 102 103 104 105 106
test_expect_success "'ipfs block stat' with nothing from stdin doesnt crash" '
	test_expect_code 1 ipfs block stat < /dev/null 2> stat_out
'

test_expect_success "no panic in output" '
	test_expect_code 1 grep "panic" stat_out
'

107
test_done