t0040-add-and-cat.sh 2.16 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_mount
12 13 14

test_expect_success "ipfs add succeeds" '
	echo "Hello Worlds!" >mountdir/hello.txt &&
15
	ipfs add mountdir/hello.txt >actual
16 17 18 19
'

test_expect_success "ipfs add output looks good" '
	HASH="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
20
	echo "added $HASH mountdir/hello.txt" >expected &&
21 22 23 24
	test_cmp expected actual
'

test_expect_success "ipfs cat succeeds" '
25
	ipfs cat $HASH >actual
26 27 28 29 30 31 32
'

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

33
test_expect_success FUSE "cat ipfs/stuff succeeds" '
34 35 36
	cat ipfs/$HASH >actual
'

37
test_expect_success FUSE "cat ipfs/stuff looks good" '
38 39 40
	test_cmp expected actual
'

41 42 43 44 45 46 47 48 49
test_expect_success "go-random is installed" '
	type random
'

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

test_expect_success "sha1 of the file looks ok" '
50
	echo "885b197b01e0f7ff584458dc236cb9477d2e736d  mountdir/bigfile" >sha1_expected &&
51
	shasum mountdir/bigfile >sha1_actual &&
52 53 54 55
	test_cmp sha1_expected sha1_actual
'

test_expect_success "ipfs add bigfile succeeds" '
56
	ipfs add mountdir/bigfile >actual
57 58 59
'

test_expect_success "ipfs add bigfile output looks good" '
60
	HASH="QmWXysX1oysyjTqd5xGM2T1maBaVXnk5svQv4GKo5PsGPo" &&
61
	echo "added $HASH mountdir/bigfile" >expected &&
62 63 64 65
	test_cmp expected actual
'

test_expect_success "ipfs cat succeeds" '
66
	ipfs cat $HASH | shasum >sha1_actual
67 68
'

69 70 71 72 73 74
# this test commented out to run faster.
# uncomment to produce and examine output
# test_expect_success "ipfs cat output looks good" '
#   ipfs cat $HASH >actual &&
# 	test_cmp mountdir/bigfile actual
# '
75 76

test_expect_success "ipfs cat output shasum looks good" '
77
	echo "885b197b01e0f7ff584458dc236cb9477d2e736d  -" >sha1_expected &&
78 79 80
	test_cmp sha1_expected sha1_actual
'

81
test_expect_success FUSE "cat ipfs/bigfile succeeds" '
82
	cat ipfs/$HASH | shasum >sha1_actual
83 84
'

85
test_expect_success FUSE "cat ipfs/bigfile looks good" '
86 87 88
	test_cmp sha1_expected sha1_actual
'

89
test_kill_ipfs_daemon
90 91

test_done