Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 969b2f6

Browse files
author
Ian Campbell
committed
ci: use gotestsum for running unit tests
This allow us to output a junit test file which can be fed to Jenkins. While building we build for all the architectures we are eventually going to care about. Lastly kill a tray trailing tab in the `Makefile` which `emacs` complains about. Signed-off-by: Ian Campbell <ijc@docker.com>
1 parent f75016b commit 969b2f6

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ ENV PATH=${PATH}:/go/src/github.com/docker/app/bin/
2121
ARG DEP_VERSION=v0.5.0
2222
RUN curl -o /usr/bin/dep -L https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 && \
2323
chmod +x /usr/bin/dep
24+
ARG GOTESTSUM_VERSION=v0.3.4
25+
RUN mkdir $GOPATH/src/gotest.tools && \
26+
git clone -q https://github.com/gotestyourself/gotestsum $GOPATH/src/gotest.tools/gotestsum && \
27+
cd $GOPATH/src/gotest.tools/gotestsum && \
28+
git -C $GOPATH/src/gotest.tools/gotestsum checkout -q $GOTESTSUM_VERSION && \
29+
GO111MODULE=on GOOS=linux go build -o /usr/local/bin/gotestsum-linux gotest.tools/gotestsum && \
30+
GO111MODULE=on GOOS=darwin go build -o /usr/local/bin/gotestsum-darwin gotest.tools/gotestsum && \
31+
GO111MODULE=on GOOS=windows go build -o /usr/local/bin/gotestsum-windows.exe gotest.tools/gotestsum && \
32+
ln -s gotestsum-linux /usr/local/bin/gotestsum
2433
RUN go get -d gopkg.in/mjibson/esc.v0 && \
2534
cd /go/src/github.com/mjibson/esc && \
2635
go build -v -o /usr/bin/esc . && \

Jenkinsfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ pipeline {
115115
}
116116
post {
117117
always {
118+
archiveArtifacts 'src/github.com/docker/app/_build/test-results/*.xml'
119+
junit 'src/github.com/docker/app/_build/test-results/*.xml'
118120
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG-coverage'
119121
deleteDir()
120122
}

Jenkinsfile.baguette

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pipeline {
101101
}
102102
post {
103103
always {
104+
archiveArtifacts 'src/github.com/docker/app/_build/test-results/*.xml'
105+
junit 'src/github.com/docker/app/_build/test-results/*.xml'
104106
sh 'docker rmi docker/cnab-app-base:$BUILD_TAG-coverage'
105107
deleteDir()
106108
}

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ ifeq ($(OS),Windows_NT)
2424
EXEC_EXT := .exe
2525
endif
2626

27+
TEST_RESULTS_DIR = _build/test-results
2728
STATIC_FLAGS= CGO_ENABLED=0
2829
GO_BUILD = $(STATIC_FLAGS) go build -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
2930
GO_TEST = $(STATIC_FLAGS) go test -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
31+
GO_TESTSUM = $(STATIC_FLAGS) gotestsum --junitfile $(TEST_RESULTS_DIR)/$(1) -- -tags=$(BUILDTAGS) -ldflags=$(LDFLAGS)
3032

3133
all: bin/$(BIN_NAME) test
3234

@@ -79,15 +81,17 @@ test-e2e: bin/$(BIN_NAME) ## run end-to-end tests
7981

8082
test-unit: ## run unit tests
8183
@echo "Running unit tests..."
82-
$(GO_TEST) $(shell go list ./... | grep -vE '/e2e')
84+
@$(call mkdir,$(TEST_RESULTS_DIR))
85+
$(call GO_TESTSUM,unit.xml) $(shell go list ./... | grep -vE '/e2e')
8386

8487
coverage-bin:
8588
CGO_ENABLED=0 go test -tags="$(BUILDTAGS) testrunmain" -ldflags=$(LDFLAGS) -coverpkg="./..." -c -o _build/$(BIN_NAME).cov ./cmd/docker-app
8689

8790
coverage-test-unit:
8891
@echo "Running unit tests (coverage)..."
8992
@$(call mkdir,_build/cov)
90-
$(GO_TEST) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e')
93+
@$(call mkdir,$(TEST_RESULTS_DIR))
94+
$(call GO_TESTSUM,unit-coverage.xml) -cover -test.coverprofile=_build/cov/unit.out $(shell go list ./... | grep -vE '/e2e')
9195

9296
coverage-test-e2e: coverage-bin
9397
@echo "Running e2e tests (coverage)..."

docker.Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ tars:
8787
test: test-unit test-e2e ## run all tests
8888

8989
test-unit: build_dev_image ## run unit tests
90-
docker run --rm $(DEV_IMAGE_NAME) make EXPERIMENTAL=$(EXPERIMENTAL) test-unit
90+
@$(call mkdir,_build/test-results)
91+
docker run --rm -v $(CURDIR)/_build/test-results:/test-results $(DEV_IMAGE_NAME) make EXPERIMENTAL=$(EXPERIMENTAL) test-unit
9192

9293
test-e2e: build_dev_image invocation-image ## run end-to-end tests
9394
docker run -v /var/run:/var/run:ro --rm --network="host" $(DEV_IMAGE_NAME) make EXPERIMENTAL=$(EXPERIMENTAL) bin/$(BIN_NAME) test-e2e
@@ -97,6 +98,7 @@ coverage: build_dev_image ## run tests with coverage
9798
@$(call mkdir,_build)
9899
docker run -v /var/run:/var/run:ro --name $(COV_CTNR_NAME) --network="host" -t $(DEV_IMAGE_NAME) make COMMIT=${COMMIT} TAG=${TAG} EXPERIMENTAL=$(EXPERIMENTAL) coverage
99100
docker cp $(COV_CTNR_NAME):$(PKG_PATH)/_build/cov/ ./_build/ci-cov
101+
docker cp $(COV_CTNR_NAME):$(PKG_PATH)/_build/test-results/ ./_build/test-results
100102
docker rm $(COV_CTNR_NAME)
101103

102104
gradle-test:
@@ -124,7 +126,7 @@ vendor: build_dev_image
124126
clean-vendor-cache:
125127
docker rm -f docker-app-vendoring || true
126128
docker volume rm -f docker-app-vendor-cache
127-
129+
128130
check-vendor: build_dev_image
129131
$(info Check Vendoring...)
130132
docker run --rm $(DEV_IMAGE_NAME) sh -c "make vendor && hack/check-git-diff vendor"

0 commit comments

Comments
 (0)