diff --git a/test/.gitignore b/test/.gitignore index 51511d1f8f3..3103c757ec0 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,2 @@ test-results/ +trash directory.*.sh/ diff --git a/test/t0030-mount.sh b/test/t0030-mount.sh new file mode 100755 index 00000000000..cca3fc1b243 --- /dev/null +++ b/test/t0030-mount.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Copyright (c) 2014 Christian Couder +# MIT Licensed; see the LICENSE file in this repository. +# + +test_description="Test mount command" + +. ./test-lib.sh + +test_launch_ipfs_mount + +test_kill_ipfs_mount + +test_done diff --git a/test/t0040-add-and-cat.sh b/test/t0040-add-and-cat.sh new file mode 100755 index 00000000000..cf2f0b4d18b --- /dev/null +++ b/test/t0040-add-and-cat.sh @@ -0,0 +1,84 @@ +#!/bin/sh +# +# Copyright (c) 2014 Christian Couder +# MIT Licensed; see the LICENSE file in this repository. +# + +test_description="Test add and cat commands" + +. ./test-lib.sh + +test_launch_ipfs_mount + +test_expect_success "ipfs add succeeds" ' + echo "Hello Worlds!" >mountdir/hello.txt && + ipfs add mountdir/hello.txt >actual +' + +test_expect_success "ipfs add output looks good" ' + HASH="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" && + echo "added $HASH $(pwd)/mountdir/hello.txt" >expected && + test_cmp expected actual +' + +test_expect_success "ipfs cat succeeds" ' + ipfs cat $HASH >actual +' + +test_expect_success "ipfs cat output looks good" ' + echo "Hello Worlds!" >expected && + test_cmp expected actual +' + +test_expect_success "cat ipfs/stuff succeeds" ' + cat ipfs/$HASH >actual +' + +test_expect_success "cat ipfs/stuff looks good" ' + test_cmp expected actual +' + +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" ' + echo "54dc0dbbc353b2ffb745285793f89af0c9d98449 mountdir/bigfile" >sha1_expected && + sha1sum 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="QmeZVkWkDu4W1vxWdDgUbqKYba9K3u45hJEdPA4Wr2sHZz" && + echo "added $HASH $(pwd)/mountdir/bigfile" >expected && + test_cmp expected actual +' + +test_expect_success "ipfs cat succeeds" ' + ipfs cat $HASH | sha1sum >sha1_actual +' + +test_expect_success "ipfs cat output looks good" ' + echo "54dc0dbbc353b2ffb745285793f89af0c9d98449 -" >sha1_expected && + test_cmp sha1_expected sha1_actual +' + +test_expect_success "cat ipfs/bigfile succeeds" ' + cat ipfs/$HASH | sha1sum >sha1_actual +' + +test_expect_success "cat ipfs/bigfile looks good" ' + test_cmp sha1_expected sha1_actual +' + +test_kill_ipfs_mount + +test_done diff --git a/test/test-lib.sh b/test/test-lib.sh index 307ed2e7fdf..ee860f85556 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -16,3 +16,49 @@ # Please put go-ipfs specific shell functions below +test_cmp_repeat_10_sec() { + for i in 1 2 3 4 5 6 7 8 9 10 + do + test_cmp "$1" "$2" && return + sleep 1 + done + test_cmp "$1" "$2" +} + +test_launch_ipfs_mount() { + + test_expect_success "ipfs init succeeds" ' + export IPFS_DIR="$(pwd)/.go-ipfs" && + ipfs init -b=2048 + ' + + test_expect_success "prepare config" ' + mkdir mountdir ipfs ipns && + ipfs config Mounts.IPFS "$(pwd)/ipfs" && + ipfs config Mounts.IPNS "$(pwd)/ipns" + ' + + test_expect_success "ipfs mount succeeds" ' + ipfs mount mountdir >actual & + ' + + test_expect_success "ipfs mount output looks good" ' + IPFS_PID=$! && + echo "mounting ipfs at $(pwd)/ipfs" >expected && + echo "mounting ipns at $(pwd)/ipns" >>expected && + test_cmp_repeat_10_sec expected actual + ' +} + +test_kill_ipfs_mount() { + + test_expect_success "ipfs mount is still running" ' + kill -0 $IPFS_PID + ' + + test_expect_success "ipfs mount can be killed" ' + kill $IPFS_PID && + sleep 1 && + ! kill -0 $IPFS_PID 2>/dev/null + ' +}