*: add basic test script + travis hook
authorJonathan Boulle <jonathanboulle@gmail.com>
Mon, 7 Sep 2015 23:15:18 +0000 (16:15 -0700)
committerJonathan Boulle <jonathanboulle@gmail.com>
Mon, 7 Sep 2015 23:21:53 +0000 (16:21 -0700)
Adds a simple test script, mostly to perform gofmt and govet checking;
currently tests only exist for the DHCP plugin.

.travis.yml [new file with mode: 0644]
test [new file with mode: 0755]

diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..ba206fd
--- /dev/null
@@ -0,0 +1,14 @@
+language: go
+matrix:
+  include:
+    - go: 1.4
+      env: TOOLS_CMD=golang.org/x/tools/cmd
+
+install:
+ - go get ${TOOLS_CMD}/vet
+
+script:
+ - ./test
+
+notifications:
+  email: false
diff --git a/test b/test
new file mode 100755 (executable)
index 0000000..838880e
--- /dev/null
+++ b/test
@@ -0,0 +1,52 @@
+#!/bin/bash -e
+#
+# Run all CNI tests 
+#   ./test
+#   ./test -v
+#
+# Run tests for one package
+#   PKG=./plugins/ipam/dhcp ./test
+#
+
+source ./build
+
+TESTABLE="plugins/ipam/dhcp"
+FORMATTABLE="$TESTABLE pkg/ip pkg/ns pkg/plugin pkg/skel plugins/ipam/host-local plugins/main/bridge plugins/meta/flannel"
+
+# user has not provided PKG override
+if [ -z "$PKG" ]; then
+       TEST=$TESTABLE
+       FMT=$FORMATTABLE
+
+# user has provided PKG override
+else
+       # strip out slashes and dots from PKG=./foo/
+       TEST=${PKG//\//}
+       TEST=${TEST//./}
+
+       # only run gofmt on packages provided by user
+       FMT="$TEST"
+fi
+
+# split TEST into an array and prepend REPO_PATH to each local package
+split=(${TEST// / })
+TEST=${split[@]/#/${REPO_PATH}/}
+
+echo "Running tests..."
+go test ${COVER} $@ ${TEST}
+
+echo "Checking gofmt..."
+fmtRes=$(gofmt -l $FMT)
+if [ -n "${fmtRes}" ]; then
+       echo -e "gofmt checking failed:\n${fmtRes}"
+       exit 255
+fi
+
+echo "Checking govet..."
+vetRes=$(go vet $TEST)
+if [ -n "${vetRes}" ]; then
+       echo -e "govet checking failed:\n${vetRes}"
+       exit 255
+fi
+
+echo "Success"