Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 2c8c2ec

Browse files
author
Bogdan Drutu
authored
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.
1 parent d62d215 commit 2c8c2ec

File tree

31 files changed

+410
-12
lines changed

31 files changed

+410
-12
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ bin/
1818
# order to simplify docker build commands. Ignore these files if proper clean up fails.
1919
cmd/ocagent/ocagent_linux
2020
cmd/occollector/occollector_linux
21+
22+
# Coverage
23+
coverage.txt
24+
coverage.html

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ install:
1313
- make install-tools
1414

1515
script:
16-
- make fmt
17-
- make lint
18-
- make test-with-coverage
16+
- make travis-ci
1917

2018
after_success:
2119
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
ALL_SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
1+
# More exclusions can be added similar with: -not -path './vendor/*'
2+
ALL_SRC := $(shell find . -name '*.go' \
3+
-not -path './vendor/*' \
4+
-type f | sort)
5+
6+
# ALL_PKGS is used with 'go cover'
7+
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
28

39
GOTEST_OPT?=-v -race -timeout 30s
410
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
511
GOTEST=go test
612
GOFMT=gofmt
713
GOLINT=golint
14+
GOVET=go vet
815
GOOS=$(shell go env GOOS)
916

1017
GIT_SHA=$(shell git rev-parse --short HEAD)
@@ -15,18 +22,32 @@ BUILD_X2=-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION)
1522
endif
1623
BUILD_INFO=-ldflags "${BUILD_X1} ${BUILD_X2}"
1724

18-
.DEFAULT_GOAL := default_goal
25+
all_pkgs:
26+
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
27+
28+
all_srcs:
29+
@echo $(ALL_SRC) | tr ' ' '\n' | sort
1930

20-
.PHONY: default_goal
21-
default_goal: fmt lint test
31+
.DEFAULT_GOAL := fmt-vet-lint-test
32+
33+
.PHONY: fmt-vet-lint-test
34+
fmt-vet-lint-test: fmt vet lint test
2235

2336
.PHONY: test
2437
test:
25-
$(GOTEST) $(GOTEST_OPT) ./...
38+
$(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
39+
40+
.PHONY: travis-ci
41+
travis-ci: fmt vet lint test-with-cover
2642

27-
.PHONY: test-with-coverage
28-
test-with-coverage:
29-
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) ./...
43+
.PHONY: test-with-cover
44+
test-with-cover:
45+
@echo Verifying that all packages have test files to count in coverage
46+
@scripts/check-test-files.sh $(subst github.com/census-instrumentation/opencensus-service/,./,$(ALL_PKGS))
47+
@echo pre-compiling tests
48+
@time go test -i $(ALL_PKGS)
49+
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
50+
go tool cover -html=coverage.txt -o coverage.html
3051

3152
.PHONY: fmt
3253
fmt:
@@ -35,15 +56,30 @@ fmt:
3556
echo "$(GOFMT) FAILED => gofmt the following files:\n"; \
3657
echo "$$FMTOUT\n"; \
3758
exit 1; \
59+
else \
60+
echo "Fmt finished successfully"; \
3861
fi
3962

4063
.PHONY: lint
4164
lint:
42-
@LINTOUT=`$(GOLINT) ./... 2>&1`; \
65+
@LINTOUT=`$(GOLINT) $(ALL_PKGS) 2>&1`; \
4366
if [ "$$LINTOUT" ]; then \
4467
echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \
4568
echo "$$LINTOUT\n"; \
4669
exit 1; \
70+
else \
71+
echo "Lint finished successfully"; \
72+
fi
73+
74+
.PHONY: vet
75+
vet:
76+
@VETOUT=`$(GOVET) ./... 2>&1`; \
77+
if [ "$$VETOUT" ]; then \
78+
echo "$(GOVET) FAILED => clean the following vet errors:\n"; \
79+
echo "$$VETOUT\n"; \
80+
exit 1; \
81+
else \
82+
echo "Vet finished successfully"; \
4783
fi
4884

4985
.PHONY: install-tools
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package collector
16+
17+
// TODO: Delete me when tests are added.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package sender
16+
17+
// TODO: Delete me when tests are added.

data/empty_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package data
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package datadogexporter
16+
17+
// TODO: Add tests.

exporter/empty_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package exporter
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package exporterwrapper
16+
17+
// TODO: Add tests.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package honeycombexporter
16+
17+
// TODO: Add tests.

0 commit comments

Comments
 (0)