github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/test/lib/test-lib.sh (about)

     1  # Test framework for go-ipfs
     2  #
     3  # Copyright (c) 2014 Christian Couder
     4  # MIT Licensed; see the LICENSE file in this repository.
     5  #
     6  # We are using sharness (https://github.com/mlafeldt/sharness)
     7  # which was extracted from the Git test framework.
     8  
     9  # use the ipfs tool to test against
    10  
    11  # add current directory to path, for ipfs tool.
    12  PATH=$(pwd)/bin:${PATH}
    13  
    14  # assert the `ipfs` we're using is the right one.
    15  if test `which ipfs` != $(pwd)/bin/ipfs; then
    16  	echo >&2 "Cannot find the tests' local ipfs tool."
    17  	echo >&2 "Please check test and ipfs tool installation."
    18  	exit 1
    19  fi
    20  
    21  SHARNESS_LIB="lib/sharness/sharness.sh"
    22  
    23  . "$SHARNESS_LIB" || {
    24  	echo >&2 "Cannot source: $SHARNESS_LIB"
    25  	echo >&2 "Please check Sharness installation."
    26  	exit 1
    27  }
    28  
    29  # Please put go-ipfs specific shell functions below
    30  
    31  test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE
    32  
    33  test_cmp_repeat_10_sec() {
    34  	for i in 1 2 3 4 5 6 7 8 9 10
    35  	do
    36  		test_cmp "$1" "$2" && return
    37  		sleep 1
    38  	done
    39  	test_cmp "$1" "$2"
    40  }
    41  
    42  test_launch_ipfs_mount() {
    43  
    44  	test_expect_success "ipfs init succeeds" '
    45  		export IPFS_DIR="$(pwd)/.go-ipfs" &&
    46  		ipfs init -b=2048
    47  	'
    48  
    49  	test_expect_success "prepare config" '
    50  		mkdir mountdir ipfs ipns &&
    51  		ipfs config Mounts.IPFS "$(pwd)/ipfs" &&
    52  		ipfs config Mounts.IPNS "$(pwd)/ipns"
    53  	'
    54  
    55  	test_expect_success FUSE "ipfs mount succeeds" '
    56  		ipfs mount mountdir >actual &
    57  	'
    58  
    59  	test_expect_success FUSE "ipfs mount output looks good" '
    60  		IPFS_PID=$! &&
    61  		echo "mounting ipfs at $(pwd)/ipfs" >expected &&
    62  		echo "mounting ipns at $(pwd)/ipns" >>expected &&
    63  		test_cmp_repeat_10_sec expected actual
    64  	'
    65  }
    66  
    67  test_kill_ipfs_mount() {
    68  
    69  	test_expect_success FUSE "ipfs mount is still running" '
    70  		kill -0 $IPFS_PID
    71  	'
    72  
    73  	test_expect_success FUSE "ipfs mount can be killed" '
    74  		kill $IPFS_PID &&
    75  		sleep 1 &&
    76  		! kill -0 $IPFS_PID 2>/dev/null
    77  	'
    78  }