diff --git a/.travis.yml b/.travis.yml index ecf595da0..117f3bc1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ go: - tip script: - - go test -v ./... + - make test env: TEST_NO_FUSE=1 diff --git a/Makefile b/Makefile index a6496bd45..dcb369941 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,15 @@ godep: # ./... performs operation on all packages in tree vendor: godep godep save -r ./... + + +install: + cd cmd/ipfs && go install + +test: test_go test_sharness + +test_go: + go test ./... + +test_sharness: + cd test/ && make diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 369fcee75..ed444b100 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -82,7 +82,7 @@ func (bs *bitswap) Block(parent context.Context, k u.Key) (*blocks.Block, error) log.Debugf("Get Block %v", k) now := time.Now() defer func() { - log.Errorf("GetBlock took %f secs", time.Now().Sub(now).Seconds()) + log.Debugf("GetBlock took %f secs", time.Now().Sub(now).Seconds()) }() ctx, cancelFunc := context.WithCancel(parent) diff --git a/test/Makefile b/test/Makefile index 7e6381794..85be73662 100644 --- a/test/Makefile +++ b/test/Makefile @@ -6,7 +6,7 @@ T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) -all: clean $(T) aggregate +all: clean deps $(T) aggregate clean: @echo "*** $@ ***" @@ -20,4 +20,21 @@ aggregate: @echo "*** $@ ***" ./test-aggregate-results.sh -.PHONY: all clean $(T) aggregate +deps: ipfs sharness.sh random + +# phony to ensure we re-build it every time we run tests +ipfs: + cd ../cmd/ipfs && go build + cp ../cmd/ipfs/ipfs ipfs + +sharness.sh: + @echo "*** installing $@ ***" + ./install-sharness.sh + +.PHONY: all clean $(T) aggregate ipfs + +random: + @echo "*** installing $@ ***" + go get github.com/jbenet/go-random/random + go install github.com/jbenet/go-random/random + cp `which random` random diff --git a/test/install-sharness.sh b/test/install-sharness.sh new file mode 100755 index 000000000..871ebb690 --- /dev/null +++ b/test/install-sharness.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# install sharness.sh +# +# Copyright (c) 2014 Juan Batiz-Benet +# MIT Licensed; see the LICENSE file in this repository. +# + +# settings +version=50229a79ba22b2f13ccd82451d86570fecbd194c +urlprefix=https://raw.githubusercontent.com/mlafeldt/sharness/$version + +# files to download +sfile=sharness.sh +shash=eeaf96630fc25ec58fb678b64ef9772d5eb92f64 + +afile=aggregate-results.sh +ahash=948d6bc03222c5c00a1ed048068508d5ea1cce59 + +verified_download() { + file=$1 + hash1=$2 + url=$urlprefix/$file + + # download it + wget -q $url -O $file.test + + # verify it's the right file + hash2=`cat $file.test | shasum | cut -c1-40` + if test "$hash1" != "$hash2"; then + echo "$file verification failed:" + echo " $hash1 != $hash2" + return -1 + fi + return 0 +} + + +verified_download "$sfile" "$shash"; sok=$? +verified_download "$afile" "$ahash"; aok=$? +if test "$sok" != 0 || test "$aok" != 0; then + rm $afile.test + rm $sfile.test + exit -1 +fi + +# ok, move things into place +mv $sfile.test $sfile +mv $afile.test $afile +chmod +x $sfile +chmod +x $afile +exit 0 diff --git a/test/t0030-mount.sh b/test/t0030-mount.sh index cca3fc1b2..ddb187f72 100755 --- a/test/t0030-mount.sh +++ b/test/t0030-mount.sh @@ -8,6 +8,13 @@ test_description="Test mount command" . ./test-lib.sh +# if in travis CI, dont test mount (no fuse) +if ! test_have_prereq FUSE; then + skip_all='skipping mount tests, fuse not available' + + test_done +fi + test_launch_ipfs_mount test_kill_ipfs_mount diff --git a/test/t0040-add-and-cat.sh b/test/t0040-add-and-cat.sh index 34036f9da..3091afc2e 100755 --- a/test/t0040-add-and-cat.sh +++ b/test/t0040-add-and-cat.sh @@ -30,11 +30,11 @@ test_expect_success "ipfs cat output looks good" ' test_cmp expected actual ' -test_expect_success "cat ipfs/stuff succeeds" ' +test_expect_success FUSE "cat ipfs/stuff succeeds" ' cat ipfs/$HASH >actual ' -test_expect_success "cat ipfs/stuff looks good" ' +test_expect_success FUSE "cat ipfs/stuff looks good" ' test_cmp expected actual ' @@ -71,11 +71,11 @@ test_expect_success "ipfs cat output looks good" ' test_cmp sha1_expected sha1_actual ' -test_expect_success "cat ipfs/bigfile succeeds" ' +test_expect_success FUSE "cat ipfs/bigfile succeeds" ' cat ipfs/$HASH | shasum >sha1_actual ' -test_expect_success "cat ipfs/bigfile looks good" ' +test_expect_success FUSE "cat ipfs/bigfile looks good" ' test_cmp sha1_expected sha1_actual ' diff --git a/test/test-aggregate-results.sh b/test/test-aggregate-results.sh index fdac06dea..eea4b7154 100755 --- a/test/test-aggregate-results.sh +++ b/test/test-aggregate-results.sh @@ -6,9 +6,7 @@ # MIT Licensed; see the LICENSE file in this repository. # -. ./test-sharness-config.sh - -SHARNESS_AGGREGATE="$SHARNESS_DIRECTORY/aggregate-results.sh" +SHARNESS_AGGREGATE="./aggregate-results.sh" test -f "$SHARNESS_AGGREGATE" || { echo >&2 "Cannot find: $SHARNESS_AGGREGATE" diff --git a/test/test-lib.sh b/test/test-lib.sh index ee860f855..d9c19395f 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -6,7 +6,19 @@ # We are using sharness (https://github.com/mlafeldt/sharness) # which was extracted from the Git test framework. -. ./test-sharness-config.sh +# use the ipfs tool to test against + +# add current directory to path, for ipfs tool. +PATH=$(pwd):${PATH} + +# assert the `ipfs` we're using is the right one. +if test `which ipfs` != $(pwd)/ipfs; then + echo >&2 "Cannot find the tests' local ipfs tool." + echo >&2 "Please check test and ipfs tool installation." + exit 1 +fi + +SHARNESS_LIB="./sharness.sh" . "$SHARNESS_LIB" || { echo >&2 "Cannot source: $SHARNESS_LIB" @@ -16,6 +28,8 @@ # Please put go-ipfs specific shell functions below +test "$TEST_NO_FUSE" != 1 && test_set_prereq FUSE + test_cmp_repeat_10_sec() { for i in 1 2 3 4 5 6 7 8 9 10 do @@ -38,11 +52,11 @@ test_launch_ipfs_mount() { ipfs config Mounts.IPNS "$(pwd)/ipns" ' - test_expect_success "ipfs mount succeeds" ' + test_expect_success FUSE "ipfs mount succeeds" ' ipfs mount mountdir >actual & ' - test_expect_success "ipfs mount output looks good" ' + test_expect_success FUSE "ipfs mount output looks good" ' IPFS_PID=$! && echo "mounting ipfs at $(pwd)/ipfs" >expected && echo "mounting ipns at $(pwd)/ipns" >>expected && @@ -52,11 +66,11 @@ test_launch_ipfs_mount() { test_kill_ipfs_mount() { - test_expect_success "ipfs mount is still running" ' + test_expect_success FUSE "ipfs mount is still running" ' kill -0 $IPFS_PID ' - test_expect_success "ipfs mount can be killed" ' + test_expect_success FUSE "ipfs mount can be killed" ' kill $IPFS_PID && sleep 1 && ! kill -0 $IPFS_PID 2>/dev/null diff --git a/test/test-sharness-config.sh b/test/test-sharness-config.sh deleted file mode 100644 index 4c26c8985..000000000 --- a/test/test-sharness-config.sh +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2014 Christian Couder -# MIT Licensed; see the LICENSE file in this repository. -# -# We are using sharness (https://github.com/mlafeldt/sharness) -# which was extracted from the Git test framework. - -# You need either sharness to be installed system-wide or -# to set the SHARNESS_DIRECTORY environment variable properly. - -if test -z "$SHARNESS_DIRECTORY" -then - SHARNESS_DIRECTORY=/usr/local/share/sharness -fi - -SHARNESS_LIB="$SHARNESS_DIRECTORY/sharness.sh" - -test -f "$SHARNESS_LIB" || { - echo >&2 "Cannot find sharness.sh in: $SHARNESS_DIRECTORY" - echo >&2 "Please install Sharness system-wide or set the" - echo >&2 "SHARNESS_DIRECTORY environment variable." - echo >&2 "See: https://github.com/mlafeldt/sharness" - exit 1 -}