Skip to content

Commit

Permalink
Verify that all packages have tests (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro committed Jan 6, 2018
1 parent 32bc1b7 commit d2f85a4
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 10 deletions.
31 changes: 21 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROJECT_ROOT=github.com/jaegertracing/jaeger
TOP_PKGS := $(shell glide novendor | grep -v -e ./thrift-gen/... -e swagger-gen... -e ./examples/... -e ./scripts/...)

# all .go files that don't exist in hidden directories
ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e swagger-gen \
ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen -e swagger-gen -e examples -e doc.go \
-e ".*/\..*" \
-e ".*/_.*" \
-e ".*/mocks.*")
Expand Down Expand Up @@ -41,6 +41,7 @@ SWAGGER_GEN_DIR=swagger-gen

PASS=$(shell printf "\033[32mPASS\033[0m")
FAIL=$(shell printf "\033[31mFAIL\033[0m")
FIXME=$(shell printf "\033[31mFIXME\033[0m")
COLORIZE=$(SED) ''/PASS/s//$(PASS)/'' | $(SED) ''/FAIL/s//$(FAIL)/''
DOCKER_NAMESPACE?=jaegertracing
DOCKER_TAG?=latest
Expand Down Expand Up @@ -76,6 +77,24 @@ integration-test: go-gen
storage-integration-test: go-gen
$(GOTEST) ./plugin/storage/integration/...

all-pkgs:
@echo $(ALL_PKGS) | tr ' ' '\n' | sort

cvr-pkgs:
go list $(TOP_PKGS)

.PHONY: cover
cover: nocover
@echo pre-compiling tests
@time go test -i $(ALL_PKGS)
@./scripts/cover.sh $(shell go list $(TOP_PKGS))
go tool cover -html=cover.out -o cover.html

.PHONY: nocover
nocover:
@echo Verifying that all packages have test files to count in coverage
@scripts/check-test-files.sh $(subst github.com/jaegertracing/jaeger/,./,$(ALL_PKGS)) | $(SED) ''/FIXME/s//$(FIXME)/''

.PHONY: fmt
fmt:
$(GOFMT) -e -s -l -w $(ALL_SRC)
Expand Down Expand Up @@ -172,11 +191,6 @@ build-crossdock: docker-no-ui
build-crossdock-fresh: build-crossdock-linux
make crossdock-fresh

.PHONY: cover
cover:
./scripts/cover.sh $(shell go list $(TOP_PKGS))
go tool cover -html=cover.out -o cover.html

.PHONY: install-ci
install-ci: install
go get github.com/wadey/gocovmerge
Expand All @@ -186,10 +200,7 @@ install-ci: install
go get github.com/sectioneight/md-to-godoc

.PHONY: test-ci
test-ci: build-examples lint
@echo pre-compiling tests
@time go test -i $(ALL_PKGS)
@./scripts/cover.sh $(shell go list $(TOP_PKGS))
test-ci: build-examples lint cover

# TODO at the moment we're not generating tchan_*.go files
.PHONY: thrift
Expand Down
1 change: 1 addition & 0 deletions cmd/agent/app/httpserver/thrift-0.9.2/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thrift-generated files
21 changes: 21 additions & 0 deletions cmd/collector/app/sampling/model/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2018 The Jaeger 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 model

// import "testing"

// func TestNothing(t *testing.T) {
// // just get the code coverage
// }
2 changes: 2 additions & 0 deletions cmd/flags/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FIXME

1 change: 1 addition & 0 deletions pkg/cassandra/config/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requires connection to Cassandra
15 changes: 15 additions & 0 deletions pkg/cassandra/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018 The Jaeger 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 cassandra
1 change: 1 addition & 0 deletions pkg/cassandra/gocql/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requires connection to Cassandra
1 change: 1 addition & 0 deletions pkg/cassandra/gocql/testutils/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIXME
15 changes: 15 additions & 0 deletions pkg/distributedlock/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018 The Jaeger 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 distributedlock
1 change: 1 addition & 0 deletions pkg/es/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIXME
1 change: 1 addition & 0 deletions pkg/es/config/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requires connection to Elasticsearch
2 changes: 2 additions & 0 deletions pkg/version/.nocover
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FIXME

38 changes: 38 additions & 0 deletions scripts/check-test-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -euo pipefail

NO_TEST_FILE_DIRS=""
for dir in $*; do
mainFile=$(find ${dir} -depth 1 -name 'main.go')
testFiles=$(find ${dir} -depth 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}"
continue
fi
# if [ -e ${dir}/main.go ]; then
# 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 "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 ${NO_TEST_FILE_DIRS} | tr ' ' '\n' >&2
exit 1
fi
15 changes: 15 additions & 0 deletions storage/dependencystore/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018 The Jaeger 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 dependencystore
15 changes: 15 additions & 0 deletions storage/samplingstore/empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018 The Jaeger 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 samplingstore

0 comments on commit d2f85a4

Please sign in to comment.