Browse code

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 authored on 2017/07/06 06:15:59
Showing 5 changed files
... ...
@@ -132,7 +132,7 @@ if \
132 132
 	command -v gcc &> /dev/null \
133 133
 	&& ! ( echo -e  '#include <libdevmapper.h>\nint main() { dm_task_deferred_remove(NULL); }'| gcc -xc - -o /dev/null -ldevmapper &> /dev/null ) \
134 134
 ; then
135
-    DOCKER_BUILDTAGS+=' libdm_no_deferred_remove'
135
+	DOCKER_BUILDTAGS+=' libdm_no_deferred_remove'
136 136
 fi
137 137
 
138 138
 # Use these flags when compiling the tests and final binary
... ...
@@ -158,8 +158,8 @@ fi
158 158
 ORIG_BUILDFLAGS+=( $REBUILD_FLAG )
159 159
 
160 160
 BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" )
161
-# Test timeout.
162 161
 
162
+# Test timeout.
163 163
 if [ "${DOCKER_ENGINE_GOARCH}" == "arm" ]; then
164 164
 	: ${TIMEOUT:=10m}
165 165
 elif [ "${DOCKER_ENGINE_GOARCH}" == "windows" ]; then
... ...
@@ -4,10 +4,9 @@ Each script is named after the bundle it creates.
4 4
 They should not be called directly - instead, pass it as argument to make.sh, for example:
5 5
 
6 6
 ```
7
-./hack/make.sh test
8 7
 ./hack/make.sh binary ubuntu
9 8
 
10
-# Or to run all bundles:
9
+# Or to run all default bundles:
11 10
 ./hack/make.sh
12 11
 ```
13 12
 
... ...
@@ -1,58 +1,6 @@
1 1
 #!/usr/bin/env bash
2 2
 set -e
3 3
 
4
-# Run Docker's test suite, including sub-packages, and store their output as a bundle
5
-# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'.
6
-# You can use this to select certain tests to run, e.g.
7
-#
8
-#   TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit
9
-#
10
-bundle_test_unit() {
11
-	TESTFLAGS+=" -test.timeout=${TIMEOUT}"
12
-	INCBUILD="-i"
13
-	count=0
14
-	for flag in "${BUILDFLAGS[@]}"; do
15
-		if [ "${flag}" == ${INCBUILD} ]; then
16
-			unset BUILDFLAGS[${count}]
17
-			break
18
-		fi
19
-		count=$[ ${count} + 1 ]
20
-	done
4
+echo "DEPRECATED: use hack/test/unit instead of hack/make.sh test-unit" >&2
21 5
 
22
-	date
23
-	if [ -z "$TESTDIRS" ]; then
24
-		TEST_PATH=./...
25
-	else
26
-		TEST_PATH=./${TESTDIRS}
27
-	fi
28
-
29
-	source "${MAKEDIR}/.go-autogen"
30
-
31
-	if [ "$(go env GOHOSTOS)" = 'solaris' ]; then
32
-		pkg_list=$(go list -e \
33
-			-f '{{if ne .Name "github.com/docker/docker"}}
34
-				{{.ImportPath}}
35
-			    {{end}}' \
36
-			"${BUILDFLAGS[@]}" $TEST_PATH \
37
-			| grep github.com/docker/docker \
38
-			| grep -v github.com/docker/docker/vendor \
39
-			| grep -v github.com/docker/docker/daemon/graphdriver \
40
-			| grep -v github.com/docker/docker/man \
41
-			| grep -v github.com/docker/docker/integration-cli)
42
-	else
43
-		pkg_list=$(go list -e \
44
-			-f '{{if ne .Name "github.com/docker/docker"}}
45
-				{{.ImportPath}}
46
-			    {{end}}' \
47
-			"${BUILDFLAGS[@]}" $TEST_PATH \
48
-			| grep github.com/docker/docker \
49
-			| grep -v github.com/docker/docker/vendor \
50
-			| grep -v github.com/docker/docker/man \
51
-			| grep -v github.com/docker/docker/integration-cli)
52
-	fi
53
-
54
-	go test -cover -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list
55
-	go test -cover -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS github.com/docker/docker/pkg/term -test.root
56
-}
57
-
58
-bundle_test_unit 2>&1 | tee -a "$DEST/test.log"
6
+$SCRIPTDIR/test/unit 2>&1 | tee -a "$DEST/test.log"
59 7
new file mode 100755
... ...
@@ -0,0 +1,25 @@
0
+#!/usr/bin/env bash
1
+#
2
+# Run unit tests
3
+#
4
+# TESTFLAGS - add additional test flags. Ex:
5
+#
6
+#   TESTFLAGS="-v -run TestBuild" hack/test/unit
7
+#
8
+# TESTDIRS - run tests for specified packages. Ex:
9
+#
10
+#    TESTDIRS="./pkg/term" hack/test/unit
11
+#
12
+set -eu -o pipefail
13
+
14
+TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
15
+BUILDFLAGS=( -tags "netgo seccomp libdm_no_deferred_remove" )
16
+TESTDIRS="${TESTDIRS:-"./..."}"
17
+
18
+exclude_paths="/vendor/|/integration-cli"
19
+if [ "$(go env GOHOSTOS)" = 'solaris' ]; then
20
+	exclude_paths="$exclude_paths|/daemon/graphdriver"
21
+fi
22
+pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
23
+
24
+go test -cover "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list
... ...
@@ -3,29 +3,20 @@
3 3
 package term
4 4
 
5 5
 import (
6
-	"flag"
7 6
 	"io/ioutil"
8 7
 	"os"
9 8
 	"testing"
10 9
 
11
-	"github.com/stretchr/testify/assert"
12 10
 	"github.com/stretchr/testify/require"
13 11
 )
14 12
 
15
-var rootEnabled bool
16
-
17
-func init() {
18
-	flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
19
-}
20
-
21 13
 // RequiresRoot skips tests that require root, unless the test.root flag has
22 14
 // been set
23 15
 func RequiresRoot(t *testing.T) {
24
-	if !rootEnabled {
16
+	if os.Getuid() != 0 {
25 17
 		t.Skip("skipping test that requires root")
26 18
 		return
27 19
 	}
28
-	assert.Equal(t, 0, os.Getuid(), "This test must be run as root.")
29 20
 }
30 21
 
31 22
 func newTtyForTest(t *testing.T) (*os.File, error) {
... ...
@@ -113,6 +104,7 @@ func TestDisableEcho(t *testing.T) {
113 113
 	defer tty.Close()
114 114
 	require.NoError(t, err)
115 115
 	state, err := SetRawTerminal(tty.Fd())
116
+	defer RestoreTerminal(tty.Fd(), state)
116 117
 	require.NoError(t, err)
117 118
 	require.NotNil(t, state)
118 119
 	err = DisableEcho(tty.Fd(), state)