github.com/duglin/docker@v1.13.1/hack/make/.integration-test-helpers (about)

     1  #!/bin/bash
     2  
     3  : ${TEST_REPEAT:=0}
     4  
     5  bundle_test_integration_cli() {
     6  	TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m"
     7  	go_test_dir integration-cli $DOCKER_INTEGRATION_TESTS_VERIFIED
     8  }
     9  
    10  # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
    11  # You can use this to select certain tests to run, e.g.
    12  #
    13  #     TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
    14  #
    15  # For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want
    16  # to run certain tests on your local host, you should run with command:
    17  #
    18  #     TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration-cli
    19  #
    20  go_test_dir() {
    21  	dir=$1
    22  	precompiled=$2
    23  	testbinary="$DEST/test.main"
    24  	testcover=()
    25  	testcoverprofile=()
    26  	(
    27  		mkdir -p "$DEST/coverprofiles"
    28  		export DEST="$ABS_DEST" # in a subshell this is safe -- our integration-cli tests need DEST, and "cd" screws it up
    29  		if [ -z $precompiled ]; then
    30  			ensure_test_dir $1 $testbinary
    31  		fi
    32  		cd "$dir"
    33  		i=0
    34  		while ((++i)); do
    35  			test_env "$testbinary" $TESTFLAGS
    36  			if [ $i -gt "$TEST_REPEAT" ]; then
    37  				break
    38  			fi
    39  			echo "Repeating test ($i)"
    40  		done
    41  	)
    42  }
    43  
    44  ensure_test_dir() {
    45  	(
    46  		# make sure a test dir will compile
    47  		dir="$1"
    48  		out="$2"
    49  		echo Building test dir: "$dir"
    50  		set -xe
    51  		cd "$dir"
    52  		go test -c -o "$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}"
    53  	)
    54  }
    55  
    56  test_env() {
    57  	(
    58  		set -xe
    59  		# use "env -i" to tightly control the environment variables that bleed into the tests
    60  		env -i \
    61  			DEST="$DEST" \
    62  			DOCKER_TLS_VERIFY="$DOCKER_TEST_TLS_VERIFY" \
    63  			DOCKER_CERT_PATH="$DOCKER_TEST_CERT_PATH" \
    64  			DOCKER_ENGINE_GOARCH="$DOCKER_ENGINE_GOARCH" \
    65  			DOCKER_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \
    66  			DOCKER_USERLANDPROXY="$DOCKER_USERLANDPROXY" \
    67  			DOCKER_HOST="$DOCKER_HOST" \
    68  			DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \
    69  			DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \
    70  			DOCKERFILE="$DOCKERFILE" \
    71  			GOPATH="$GOPATH" \
    72  			GOTRACEBACK=all \
    73  			HOME="$ABS_DEST/fake-HOME" \
    74  			PATH="$PATH" \
    75  			TEMP="$TEMP" \
    76  			TEST_IMAGE_NAMESPACE="$TEST_IMAGE_NAMESPACE" \
    77  			"$@"
    78  	)
    79  }