t0040-add-and-cat.sh 3.43 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/sh
#
# Copyright (c) 2014 Christian Couder
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test add and cat commands"

9
. lib/test-lib.sh
10

11
test_launch_ipfs_daemon_and_mount
12

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
test_expect_success "'ipfs add --help' succeeds" '
	ipfs add --help >actual
'

test_expect_success "'ipfs add --help' output looks good" '
	egrep "ipfs add.*<path>" actual
'

test_expect_success "'ipfs cat --help' succeeds" '
	ipfs cat --help >actual
'

test_expect_success "'ipfs cat --help' output looks good" '
	egrep "ipfs cat.*<ipfs-path>" actual
'

29 30
test_expect_success "ipfs add succeeds" '
	echo "Hello Worlds!" >mountdir/hello.txt &&
31
	ipfs add mountdir/hello.txt >actual
32 33 34 35
'

test_expect_success "ipfs add output looks good" '
	HASH="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
36
	echo "added $HASH mountdir/hello.txt" >expected &&
37 38 39 40
	test_cmp expected actual
'

test_expect_success "ipfs cat succeeds" '
41
	ipfs cat $HASH >actual
42 43 44 45 46 47 48
'

test_expect_success "ipfs cat output looks good" '
	echo "Hello Worlds!" >expected &&
	test_cmp expected actual
'

49
test_expect_success FUSE "cat ipfs/stuff succeeds" '
50 51 52
	cat ipfs/$HASH >actual
'

53
test_expect_success FUSE "cat ipfs/stuff looks good" '
54 55 56
	test_cmp expected actual
'

57 58 59 60
test_expect_success "go-random is installed" '
	type random
'

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
test_expect_success "generate 5MB file using go-random" '
	random 5242880 41 >mountdir/bigfile
'

test_expect_success "sha1 of the file looks ok" '
	echo "5620fb92eb5a49c9986b5c6844efda37e471660e  mountdir/bigfile" >sha1_expected &&
	shasum mountdir/bigfile >sha1_actual &&
	test_cmp sha1_expected sha1_actual
'

test_expect_success "'ipfs add bigfile' succeeds" '
	ipfs add mountdir/bigfile >actual
'

test_expect_success "'ipfs add bigfile' output looks good" '
	HASH="Qmf2EnuvFQtpFnMJb5aoVPnMx9naECPSm8AGyktmEB5rrR" &&
	echo "added $HASH mountdir/bigfile" >expected &&
	test_cmp expected actual
'

test_expect_success "'ipfs cat' succeeds" '
	ipfs cat $HASH >actual
'

test_expect_success "'ipfs cat' output looks good" '
	test_cmp mountdir/bigfile actual
'

test_expect_success FUSE "cat ipfs/bigfile succeeds" '
	cat ipfs/$HASH >actual
'

test_expect_success FUSE "cat ipfs/bigfile looks good" '
	test_cmp mountdir/bigfile actual
'

97
test_expect_success EXPENSIVE "generate 100MB file using go-random" '
98 99 100
	random 104857600 42 >mountdir/bigfile
'

101
test_expect_success EXPENSIVE "sha1 of the file looks ok" '
102
	echo "885b197b01e0f7ff584458dc236cb9477d2e736d  mountdir/bigfile" >sha1_expected &&
103
	shasum mountdir/bigfile >sha1_actual &&
104 105 106
	test_cmp sha1_expected sha1_actual
'

107
test_expect_success EXPENSIVE "ipfs add bigfile succeeds" '
108
	ipfs add mountdir/bigfile >actual
109 110
'

111
test_expect_success EXPENSIVE "ipfs add bigfile output looks good" '
112
	HASH="QmWXysX1oysyjTqd5xGM2T1maBaVXnk5svQv4GKo5PsGPo" &&
113
	echo "added $HASH mountdir/bigfile" >expected &&
114 115 116
	test_cmp expected actual
'

117
test_expect_success EXPENSIVE "ipfs cat succeeds" '
118
	ipfs cat $HASH | shasum >sha1_actual
119 120
'

121 122 123 124
test_expect_success EXPENSIVE "ipfs cat output looks good" '
	ipfs cat $HASH >actual &&
	test_cmp mountdir/bigfile actual
'
125

126
test_expect_success EXPENSIVE "ipfs cat output shasum looks good" '
127
	echo "885b197b01e0f7ff584458dc236cb9477d2e736d  -" >sha1_expected &&
128 129 130
	test_cmp sha1_expected sha1_actual
'

131
test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile succeeds" '
132
	cat ipfs/$HASH | shasum >sha1_actual
133 134
'

135
test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
136 137 138
	test_cmp sha1_expected sha1_actual
'

139
test_kill_ipfs_daemon
140 141

test_done