Browse code

Integrate unit tests into hack/make.sh

Solomon Hykes authored on 2013/09/10 08:20:30
Showing 1 changed files
... ...
@@ -18,6 +18,10 @@
18 18
 #   your checkout of the Docker repository.
19 19
 # 
20 20
 
21
+# FIXME: break down bundles into sub-scripts
22
+# FIXME: create all bundles in a single run for consistency.
23
+#	If the bundles directory already exists, fail or erase it.
24
+
21 25
 set -e
22 26
 
23 27
 # We're a nice, sexy, little shell script, and people might try to run us;
... ...
@@ -39,6 +43,9 @@ then
39 39
 	PKGVERSION="$PKGVERSION-$(date +%Y%m%d%H%M%S)-$GITCOMMIT"
40 40
 fi
41 41
 
42
+# Use these flags when compiling the tests and final binary
43
+LDFLAGS="-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w"
44
+
42 45
 PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)"
43 46
 PACKAGE_URL="http://www.docker.io/"
44 47
 PACKAGE_MAINTAINER="docker@dotcloud.com"
... ...
@@ -65,11 +72,34 @@ end script
65 65
 # Each "bundle" is a different type of build artefact: static binary, Ubuntu
66 66
 # package, etc.
67 67
 
68
+# Run Docker's test suite, including sub-packages, and store their output as a bundle
69
+bundle_test() {
70
+	mkdir -p bundles/$VERSION/test
71
+	{
72
+		date
73
+		for test_dir in $(find_test_dirs); do (
74
+			set -x
75
+			cd $test_dir
76
+			go test -v -ldflags "$LDFLAGS"
77
+		)  done
78
+	} 2>&1 | tee bundles/$VERSION/test/test.log
79
+}
80
+
81
+
82
+# This helper function walks the current directory looking for directories
83
+# holding Go test files, and prints their paths on standard output, one per
84
+# line.
85
+find_test_dirs() {
86
+       find . -name '*_test.go' | grep -v '^./vendor' |
87
+               { while read f; do dirname $f; done; } |
88
+               sort -u
89
+}
90
+
68 91
 # Build Docker as a static binary file
69 92
 bundle_binary() {
70 93
 	mkdir -p bundles/$VERSION/binary
71 94
 	go build -o bundles/$VERSION/binary/docker-$VERSION \
72
-		-ldflags "-X main.GITCOMMIT $GITCOMMIT -X main.VERSION $VERSION -d -w" \
95
+		-ldflags "$LDFLAGS" \
73 96
 		./docker
74 97
 }
75 98
 
... ...
@@ -134,6 +164,7 @@ EOF
134 134
 
135 135
 
136 136
 main() {
137
+	bundle_test
137 138
 	bundle_binary
138 139
 	bundle_ubuntu
139 140
 	cat <<EOF