Include all sources in the coverage tests. (#466)

* Include all sources in the coverage tests.

* Add go vet and run tests/lints on packages.

* Add message when fmt, lint, vet finish.
This commit is contained in:
Bogdan Drutu 2019-03-04 10:59:09 -08:00 committed by GitHub
parent d62d215ea5
commit 2c8c2ec8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 410 additions and 12 deletions

4
.gitignore vendored
View File

@ -18,3 +18,7 @@ bin/
# order to simplify docker build commands. Ignore these files if proper clean up fails.
cmd/ocagent/ocagent_linux
cmd/occollector/occollector_linux
# Coverage
coverage.txt
coverage.html

View File

@ -13,9 +13,7 @@ install:
- make install-tools
script:
- make fmt
- make lint
- make test-with-coverage
- make travis-ci
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@ -1,10 +1,17 @@
ALL_SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
# More exclusions can be added similar with: -not -path './vendor/*'
ALL_SRC := $(shell find . -name '*.go' \
-not -path './vendor/*' \
-type f | sort)
# ALL_PKGS is used with 'go cover'
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
GOTEST_OPT?=-v -race -timeout 30s
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
GOTEST=go test
GOFMT=gofmt
GOLINT=golint
GOVET=go vet
GOOS=$(shell go env GOOS)
GIT_SHA=$(shell git rev-parse --short HEAD)
@ -15,18 +22,32 @@ BUILD_X2=-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION)
endif
BUILD_INFO=-ldflags "${BUILD_X1} ${BUILD_X2}"
.DEFAULT_GOAL := default_goal
all_pkgs:
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
.PHONY: default_goal
default_goal: fmt lint test
all_srcs:
@echo $(ALL_SRC) | tr ' ' '\n' | sort
.DEFAULT_GOAL := fmt-vet-lint-test
.PHONY: fmt-vet-lint-test
fmt-vet-lint-test: fmt vet lint test
.PHONY: test
test:
$(GOTEST) $(GOTEST_OPT) ./...
$(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
.PHONY: test-with-coverage
test-with-coverage:
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) ./...
.PHONY: travis-ci
travis-ci: fmt vet lint test-with-cover
.PHONY: test-with-cover
test-with-cover:
@echo Verifying that all packages have test files to count in coverage
@scripts/check-test-files.sh $(subst github.com/census-instrumentation/opencensus-service/,./,$(ALL_PKGS))
@echo pre-compiling tests
@time go test -i $(ALL_PKGS)
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
go tool cover -html=coverage.txt -o coverage.html
.PHONY: fmt
fmt:
@ -35,15 +56,30 @@ fmt:
echo "$(GOFMT) FAILED => gofmt the following files:\n"; \
echo "$$FMTOUT\n"; \
exit 1; \
else \
echo "Fmt finished successfully"; \
fi
.PHONY: lint
lint:
@LINTOUT=`$(GOLINT) ./... 2>&1`; \
@LINTOUT=`$(GOLINT) $(ALL_PKGS) 2>&1`; \
if [ "$$LINTOUT" ]; then \
echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \
echo "$$LINTOUT\n"; \
exit 1; \
else \
echo "Lint finished successfully"; \
fi
.PHONY: vet
vet:
@VETOUT=`$(GOVET) ./... 2>&1`; \
if [ "$$VETOUT" ]; then \
echo "$(GOVET) FAILED => clean the following vet errors:\n"; \
echo "$$VETOUT\n"; \
exit 1; \
else \
echo "Vet finished successfully"; \
fi
.PHONY: install-tools

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package collector
// TODO: Delete me when tests are added.

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package sender
// TODO: Delete me when tests are added.

15
data/empty_test.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package data

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package datadogexporter
// TODO: Add tests.

15
exporter/empty_test.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright 2018, OpenCensus Authors
//
// 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.
package exporter

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package exporterwrapper
// TODO: Add tests.

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package honeycombexporter
// TODO: Add tests.

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package jaegerexporter
// TODO: Add tests.

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package kafkaexporter
// TODO: Add tests.

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package opencensusexporter
// TODO: Add tests.

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package stackdriverexporter
// TODO: Add tests.

View File

@ -0,0 +1 @@
FIXME: Move this to the receiver.

View File

@ -0,0 +1 @@
FIXME: Move this to the receiver.

View File

@ -0,0 +1 @@
FIXME: Somebody needs to fix me.

View File

@ -0,0 +1 @@
FIXME: This will get re-written and moved.

View File

@ -0,0 +1 @@
FIXME: Move this to the receiver.

View File

@ -0,0 +1 @@
FIXME: Move this to the receiver.

View File

@ -0,0 +1,15 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package compression

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package viperutils
// TODO: Add tests

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package pprofserver
// TODO: Add tests

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package testutils
// TODO: Add tests

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package version
// TODO: Add tests

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package observability_test
// Will be added in https://github.com/census-instrumentation/opencensus-service/pull/462

View File

@ -0,0 +1,17 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package observabilitytest
// TODO: Add tests

39
scripts/check-test-files.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
set -euo pipefail
COLOR_FIXME=$(printf "\033[31mFIXME\033[0m")
NO_TEST_FILE_DIRS=""
for dir in $*; do
mainFile=$(find ${dir} -maxdepth 1 -name 'main.go')
testFiles=$(find ${dir} -maxdepth 1 -name '*_test.go')
if [ -z "${testFiles}" ]; then
if [ -n "${mainFile}" ]; then
continue # single main does not require tests
fi
if [ -e ${dir}/.nocover ]; then
reason=$(cat ${dir}/.nocover)
if [ "${reason}" == "" ]; then
echo "error: ${dir}/.nocover must specify reason" >&2
exit 1
fi
echo "Package excluded from coverage: ${dir}"
echo " reason: ${reason}" | sed "/FIXME/s//${COLOR_FIXME}/"
continue
fi
if [ -z "${NO_TEST_FILE_DIRS}" ]; then
NO_TEST_FILE_DIRS="${dir}"
else
NO_TEST_FILE_DIRS="${NO_TEST_FILE_DIRS} ${dir}"
fi
fi
done
if [ -n "${NO_TEST_FILE_DIRS}" ]; then
echo "*** directories without *_test.go files:" >&2
echo ${NO_TEST_FILE_DIRS} | tr ' ' '\n' >&2
echo "error: at least one *_test.go file must be in all directories with go files so that they are counted for code coverage" >&2
echo " if no tests are possible for a package (e.g. it only defines types), create empty_test.go" >&2
exit 1
fi

View File

@ -0,0 +1,15 @@
// Copyright 2019, OpenCensus Authors
//
// 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.
package tracetranslator