From b78745f615343db7f6c9e85ca7ce0e221248c4c6 Mon Sep 17 00:00:00 2001 From: Roland Schilter Date: Thu, 8 Jun 2017 15:41:53 +0200 Subject: [PATCH] Execute tests in the prog/ directory (#2567) Also fixed prog/main_test.go (which has never been part of the test suite so far) --- Makefile | 8 +++++--- backend/Dockerfile | 1 + prog/main_test.go | 19 +++++++++++++++++++ tools/test | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 07d62e64a..d1c7d6289 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ $(RUNSVINIT): $(SCOPE_BACKEND_BUILD_UPTODATE) shell: $(SCOPE_BACKEND_BUILD_UPTODATE) /bin/bash -tests: $(SCOPE_BACKEND_BUILD_UPTODATE) $(CODECGEN_TARGETS) +tests: $(SCOPE_BACKEND_BUILD_UPTODATE) $(CODECGEN_TARGETS) prog/staticui/staticui.go prog/externalui/externalui.go ./tools/test -no-go-get lint: $(SCOPE_BACKEND_BUILD_UPTODATE) @@ -179,10 +179,12 @@ tmp/weave-scope.tgz: $(shell find client/app -type f) $(SCOPE_UI_BUILD_UPTODATE) else client/build/index.html: - cd client && npm run build + test "true" = "$(SCOPE_SKIP_UI_ASSETS)" && mkdir -p client/build || \ + { cd client && npm run build; } client/build-external/index.html: - cd client && npm run build-external + test "true" = "$(SCOPE_SKIP_UI_ASSETS)" && mkdir -p client/build-external || \ + { cd client && npm run build-external; } endif diff --git a/backend/Dockerfile b/backend/Dockerfile index 2764d9a0b..8201216e6 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:yakkety ENV GOPATH /go ENV GOVERSION 1.7 ENV PATH /go/bin:/usr/lib/go-${GOVERSION}/bin:/usr/bin:/bin:/usr/sbin:/sbin +ENV SCOPE_SKIP_UI_ASSETS true RUN apt-get update && \ apt-get install -y libpcap-dev python-requests time file shellcheck golang-${GOVERSION} git gcc-arm-linux-gnueabihf curl && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/prog/main_test.go b/prog/main_test.go index 0e8d57ebf..ca238c507 100644 --- a/prog/main_test.go +++ b/prog/main_test.go @@ -8,6 +8,25 @@ import ( "github.com/stretchr/testify/assert" ) +func TestMakeContainerFiltersFromFlags(t *testing.T) { + containerLabelFlags := containerLabelFiltersFlag{exclude: false} + containerLabelFlags.Set(`title1:label=1`) + containerLabelFlags.Set(`ti\:tle2:lab\:el=2`) + containerLabelFlags.Set(`ti tile3:label=3`) + + err := containerLabelFlags.Set("just a string") + assert.NotNil(t, err, "Invalid container label flag not detected") + + apiTopologyOptions := containerLabelFlags.apiTopologyOptions + assert.Equal(t, 3, len(apiTopologyOptions)) + assert.Equal(t, "0", apiTopologyOptions[0].Value) + assert.Equal(t, "title1", apiTopologyOptions[0].Label) + assert.Equal(t, "1", apiTopologyOptions[1].Value) + assert.Equal(t, "ti:tle2", apiTopologyOptions[1].Label) + assert.Equal(t, "2", apiTopologyOptions[2].Value) + assert.Equal(t, "ti tile3", apiTopologyOptions[2].Label) +} + func TestLogCensoredArgs(t *testing.T) { setupFlags(&flags{}) args := []string{ diff --git a/tools/test b/tools/test index 1497e7a2a..d0fde821f 100755 --- a/tools/test +++ b/tools/test @@ -74,7 +74,7 @@ fail=0 if [ -z "$TESTDIRS" ]; then # NB: Relies on paths being prefixed with './'. - TESTDIRS=($(git ls-files -- '*_test.go' | grep -vE '^(vendor|prog|experimental)/' | xargs -n1 dirname | sort -u | sed -e 's|^|./|')) + TESTDIRS=($(git ls-files -- '*_test.go' | grep -vE '^(vendor|experimental)/' | xargs -n1 dirname | sort -u | sed -e 's|^|./|')) else # TESTDIRS on the right side is not really an array variable, it # is just a string with spaces, but it is written like that to