Permalink
Browse files

*: combine unit and integration coverage [77%]

This means that we can compute the total coverage information for the
whole codebase, which is hard to do otherwise.

Signed-off-by: Aleksa Sarai <asarai@suse.com>
  • Loading branch information...
1 parent 2bcf87a commit 39261edeed23029c771488d37a4a3051961b98fb @cyphar committed Dec 28, 2016
Showing with 43 additions and 11 deletions.
  1. +1 −1 .gitignore
  2. +10 −10 Makefile
  3. 0 test/run.sh → hack/test-integration.sh
  4. +32 −0 hack/test-unit.sh
View
@@ -3,4 +3,4 @@
/vendor/src
/vendor/pkg
/vendor/github.com/cyphar/umoci
-/*.cov*
+/umoci.cov*
View
@@ -41,7 +41,7 @@ umoci.static: $(GO_SRC)
CGO_ENABLED=0 $(GO) build -ldflags "-s -w -extldflags '-static' -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -tags "$(BUILDTAGS)" -o $@ $(PROJECT)/cmd/umoci
umoci.cover: $(GO_SRC)
- $(GO) test -c -cover -coverpkg=$(PROJECT)/... -covermode=count -ldflags "-s -w -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -tags "$(BUILDTAGS)" -o $@ $(PROJECT)/cmd/umoci
+ $(GO) test -c -cover -covermode=count -coverpkg=$(PROJECT)/... -ldflags "-s -w -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -tags "$(BUILDTAGS)" -o $@ $(PROJECT)/cmd/umoci
.PHONY: update-deps
update-deps:
@@ -85,31 +85,31 @@ DOCKER_IMAGE :=opensuse/amd64:tumbleweed
umociimage:
docker build -t $(UMOCI_IMAGE) --build-arg DOCKER_IMAGE=$(DOCKER_IMAGE) .
-# FIXME: We really should make the pkg/unpriv tests less magical.
+ifndef COVERAGE
+COVERAGE := $(shell mktemp umoci.cov.XXXXXX)
+endif
+
.PHONY: test-unit
test-unit: umociimage
- docker run --rm -it -v $(PWD):/go/src/$(PROJECT) --cap-add=SYS_ADMIN $(UMOCI_IMAGE) make local-test-unit
- docker run --rm -it -v $(PWD):/go/src/$(PROJECT) -u 1000:1000 --cap-drop=all $(UMOCI_IMAGE) make local-test-unit
+ docker run --rm -it -v $(PWD):/go/src/$(PROJECT) -e COVERAGE=$(COVERAGE) --cap-add=SYS_ADMIN $(UMOCI_IMAGE) make local-test-unit
+ docker run --rm -it -v $(PWD):/go/src/$(PROJECT) -e COVERAGE=$(COVERAGE) -u 1000:1000 --cap-drop=all $(UMOCI_IMAGE) make local-test-unit
.PHONY: local-test-unit
local-test-unit:
- go test -cover -v $(PROJECT)/...
+ GO=$(GO) PROJECT=$(PROJECT) hack/test-unit.sh
.PHONY: test-integration
-ifndef COVERAGE
-COVERAGE := $(shell mktemp umoci-integration.cov.XXXXXX)
-endif
test-integration: umociimage
docker run --rm -it -v $(PWD):/go/src/$(PROJECT) -e COVERAGE=$(COVERAGE) $(UMOCI_IMAGE) make local-test-integration
docker run --rm -it -v $(PWD):/go/src/$(PROJECT) -e COVERAGE=$(COVERAGE) -u 1000:1000 --cap-drop=all $(UMOCI_IMAGE) make local-test-integration
- $(GO) tool cover -func <(egrep -v 'vendor|third_party' $(COVERAGE))
.PHONY: local-test-integration
local-test-integration: umoci.cover
- test/run.sh
+ hack/test-integration.sh
shell: umociimage
docker run --rm -it -v $(PWD):/go/src/$(PROJECT) $(UMOCI_IMAGE) bash
.PHONY: ci
ci: umoci umoci.cover validate doc test-unit test-integration
+ $(GO) tool cover -func <(egrep -v 'vendor|third_party' $(COVERAGE))
File renamed without changes.
View
@@ -0,0 +1,32 @@
+#!/bin/bash
+# umoci: Umoci Modifies Open Containers' Images
+# Copyright (C) 2016 SUSE LLC.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -ex
+
+env >&2
+
+# Set up the root and coverage directories.
+export ROOT="$(readlink -f "$(dirname "$(readlink -f "$BASH_SOURCE")")/..")"
+export COVERAGE_DIR=$(mktemp --tmpdir -d umoci-coverage.XXXXXX)
+
+# Run the tests and collate the results.
+for pkg in $(go list $PROJECT/...); do
+ $GO test -v -cover -covermode=count -coverprofile="$(mktemp --tmpdir=$COVERAGE_DIR cov.XXXXX)" -coverpkg=$PROJECT/... $pkg
+done
+$ROOT/hack/collate.awk $COVERAGE_DIR/* $COVERAGE | sponge $COVERAGE
+
+# Clean up the coverage directory.
+rm -rf "$COVERAGE_DIR"

0 comments on commit 39261ed

Please sign in to comment.