Ver código fonte

Remove test-unit from hack/make

Also remove the test flag from pkg/term and jsut checkuid directly.
Fixed a problem with a pkg/term test that was leaving the terminal in a bad
state.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 8 anos atrás
pai
commit
1fb615599a
5 arquivos alterados com 32 adições e 68 exclusões
  1. 2 2
      hack/make.sh
  2. 1 2
      hack/make/README.md
  3. 2 54
      hack/make/test-unit
  4. 25 0
      hack/test/unit
  5. 2 10
      pkg/term/term_linux_test.go

+ 2 - 2
hack/make.sh

@@ -132,7 +132,7 @@ if \
 	command -v gcc &> /dev/null \
 	&& ! ( echo -e  '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }'| gcc -xc - -o /dev/null -ldevmapper &> /dev/null ) \
 ; then
-    DOCKER_BUILDTAGS+=' libdm_no_deferred_remove'
+	DOCKER_BUILDTAGS+=' libdm_no_deferred_remove'
 fi
 
 # Use these flags when compiling the tests and final binary
@@ -158,8 +158,8 @@ fi
 ORIG_BUILDFLAGS+=( $REBUILD_FLAG )
 
 BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" )
-# Test timeout.
 
+# Test timeout.
 if [ "${DOCKER_ENGINE_GOARCH}" == "arm" ]; then
 	: ${TIMEOUT:=10m}
 elif [ "${DOCKER_ENGINE_GOARCH}" == "windows" ]; then

+ 1 - 2
hack/make/README.md

@@ -4,10 +4,9 @@ Each script is named after the bundle it creates.
 They should not be called directly - instead, pass it as argument to make.sh, for example:
 
 ```
-./hack/make.sh test
 ./hack/make.sh binary ubuntu
 
-# Or to run all bundles:
+# Or to run all default bundles:
 ./hack/make.sh
 ```
 

+ 2 - 54
hack/make/test-unit

@@ -1,58 +1,6 @@
 #!/usr/bin/env bash
 set -e
 
-# Run Docker's test suite, including sub-packages, and store their output as a bundle
-# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
-# You can use this to select certain tests to run, e.g.
-#
-#   TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
-#
-bundle_test_unit() {
-	TESTFLAGS+=" -test.timeout=${TIMEOUT}"
-	INCBUILD="-i"
-	count=0
-	for flag in "${BUILDFLAGS[@]}"; do
-		if [ "${flag}" == ${INCBUILD} ]; then
-			unset BUILDFLAGS[${count}]
-			break
-		fi
-		count=$[ ${count} + 1 ]
-	done
+echo "DEPRECATED: use hack/test/unit instead of hack/make.sh test-unit" >&2
 
-	date
-	if [ -z "$TESTDIRS" ]; then
-		TEST_PATH=./...
-	else
-		TEST_PATH=./${TESTDIRS}
-	fi
-
-	source "${MAKEDIR}/.go-autogen"
-
-	if [ "$(go env GOHOSTOS)" = 'solaris' ]; then
-		pkg_list=$(go list -e \
-			-f '{{if ne .Name "github.com/docker/docker"}}
-				{{.ImportPath}}
-			    {{end}}' \
-			"${BUILDFLAGS[@]}" $TEST_PATH \
-			| grep github.com/docker/docker \
-			| grep -v github.com/docker/docker/vendor \
-			| grep -v github.com/docker/docker/daemon/graphdriver \
-			| grep -v github.com/docker/docker/man \
-			| grep -v github.com/docker/docker/integration-cli)
-	else
-		pkg_list=$(go list -e \
-			-f '{{if ne .Name "github.com/docker/docker"}}
-				{{.ImportPath}}
-			    {{end}}' \
-			"${BUILDFLAGS[@]}" $TEST_PATH \
-			| grep github.com/docker/docker \
-			| grep -v github.com/docker/docker/vendor \
-			| grep -v github.com/docker/docker/man \
-			| grep -v github.com/docker/docker/integration-cli)
-	fi
-
-	go test -cover -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list
-	go test -cover -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS github.com/docker/docker/pkg/term -test.root
-}
-
-bundle_test_unit 2>&1 | tee -a "$DEST/test.log"
+$SCRIPTDIR/test/unit 2>&1 | tee -a "$DEST/test.log"

+ 25 - 0
hack/test/unit

@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+# Run unit tests
+#
+# TESTFLAGS - add additional test flags. Ex:
+#
+#   TESTFLAGS="-v -run TestBuild" hack/test/unit
+#
+# TESTDIRS - run tests for specified packages. Ex:
+#
+#    TESTDIRS="./pkg/term" hack/test/unit
+#
+set -eu -o pipefail
+
+TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
+BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
+TESTDIRS="${TESTDIRS:-"./..."}"
+
+exclude_paths="/vendor/|/integration-cli"
+if [ "$(go env GOHOSTOS)" = 'solaris' ]; then
+	exclude_paths="$exclude_paths|/daemon/graphdriver"
+fi
+pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
+
+go test -cover "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list

+ 2 - 10
pkg/term/term_linux_test.go

@@ -3,29 +3,20 @@
 package term
 
 import (
-	"flag"
 	"io/ioutil"
 	"os"
 	"testing"
 
-	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 )
 
-var rootEnabled bool
-
-func init() {
-	flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
-}
-
 // RequiresRoot skips tests that require root, unless the test.root flag has
 // been set
 func RequiresRoot(t *testing.T) {
-	if !rootEnabled {
+	if os.Getuid() != 0 {
 		t.Skip("skipping test that requires root")
 		return
 	}
-	assert.Equal(t, 0, os.Getuid(), "This test must be run as root.")
 }
 
 func newTtyForTest(t *testing.T) (*os.File, error) {
@@ -113,6 +104,7 @@ func TestDisableEcho(t *testing.T) {
 	defer tty.Close()
 	require.NoError(t, err)
 	state, err := SetRawTerminal(tty.Fd())
+	defer RestoreTerminal(tty.Fd(), state)
 	require.NoError(t, err)
 	require.NotNil(t, state)
 	err = DisableEcho(tty.Fd(), state)