-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced Makefile and testing implementation (#112)
- Manage go tools more efficiently within the make calls - Manage the lint tests using mgechev/revive - Added gosec tests -- TODO: fix the ~34 issues discovered - Added ineffassign tests - Added misspell tests - Fixed some lint and misspell errors - Updated travis config and added a make call to manage coveralls
- Loading branch information
1 parent
d97031b
commit 8e03e2f
Showing
6 changed files
with
112 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
ignoreGeneratedHeader = false | ||
severity = "warning" | ||
confidence = 0.8 | ||
errorCode = 1 | ||
warningCode = 1 | ||
|
||
[rule.blank-imports] | ||
[rule.context-as-argument] | ||
[rule.context-keys-type] | ||
[rule.cyclomatic] | ||
arguments = [15] | ||
[rule.dot-imports] | ||
[rule.error-return] | ||
[rule.error-strings] | ||
[rule.error-naming] | ||
[rule.exported] | ||
[rule.if-return] | ||
[rule.increment-decrement] | ||
[rule.var-naming] | ||
[rule.var-declaration] | ||
[rule.package-comments] | ||
[rule.range] | ||
[rule.receiver-naming] | ||
[rule.time-naming] | ||
[rule.unexported-return] | ||
[rule.indent-error-flow] | ||
[rule.errorf] | ||
[rule.empty-block] | ||
[rule.superfluous-else] | ||
[rule.unused-parameter] | ||
[rule.unreachable-code] | ||
[rule.redefines-builtin-id] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
language: go | ||
go: | ||
- "1.13" | ||
- '1.13' | ||
go_import_path: github.com/camptocamp/terraboard | ||
install: | ||
- make vendor | ||
- make vendor | ||
script: | ||
- make terraboard | ||
- make test | ||
- go get -u github.com/mattn/goveralls | ||
- go get -u golang.org/x/tools/cmd/cover | ||
- make coverage | ||
- "$HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=coverage.out" | ||
- make all | ||
- make publish-coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,78 @@ | ||
DEPS = $(wildcard */*.go) | ||
VERSION = $(shell git describe --always) | ||
NAME := terraboard | ||
FILES := $(wildcard */*.go) | ||
VERSION := $(shell git describe --always) | ||
.DEFAULT_GOAL := help | ||
|
||
all: test terraboard | ||
export GO111MODULE=on | ||
|
||
terraboard: main.go $(DEPS) | ||
GO111MODULE=on CGO_ENABLED=1 GOOS=linux go build \ | ||
.PHONY: setup | ||
setup: ## Install required libraries/tools for build tasks | ||
@command -v cover 2>&1 >/dev/null || GO111MODULE=off go get -u -v golang.org/x/tools/cmd/cover | ||
@command -v goimports 2>&1 >/dev/null || GO111MODULE=off go get -u -v golang.org/x/tools/cmd/goimports | ||
@command -v goveralls 2>&1 >/dev/null || GO111MODULE=off go get -u -v github.com/mattn/goveralls | ||
@command -v ineffassign 2>&1 >/dev/null || GO111MODULE=off go get -u -v github.com/gordonklaus/ineffassign | ||
@command -v misspell 2>&1 >/dev/null || GO111MODULE=off go get -u -v github.com/client9/misspell/cmd/misspell | ||
@command -v revive 2>&1 >/dev/null || GO111MODULE=off go get -u -v github.com/mgechev/revive | ||
|
||
.PHONY: fmt | ||
fmt: setup ## Format source code | ||
goimports -w $(FILES) | ||
|
||
.PHONY: lint | ||
lint: revive vet goimports ineffassign misspell ## Run all lint related tests against the codebase | ||
|
||
.PHONY: revive | ||
revive: setup ## Test code syntax with revive | ||
revive -config .revive.toml $(FILES) | ||
|
||
.PHONY: vet | ||
vet: ## Test code syntax with go vet | ||
go vet ./... | ||
|
||
.PHONY: goimports | ||
goimports: setup ## Test code syntax with goimports | ||
goimports -d $(FILES) > goimports.out | ||
@if [ -s goimports.out ]; then cat goimports.out; rm goimports.out; exit 1; else rm goimports.out; fi | ||
|
||
.PHONY: ineffassign | ||
ineffassign: setup ## Test code syntax for ineffassign | ||
ineffassign $(FILES) | ||
|
||
.PHONY: misspell | ||
misspell: setup ## Test code with misspell | ||
misspell -error $(FILES) | ||
|
||
.PHONY: test | ||
test: ## Run the tests against the codebase | ||
go test -v -race ./... | ||
|
||
.PHONY: build | ||
build: main.go $(FILES) ## Build the binary | ||
CGO_ENABLED=1 GOOS=linux go build \ | ||
-ldflags "-linkmode external -extldflags -static -X main.version=$(VERSION)" \ | ||
-o $@ $< | ||
strip $@ | ||
|
||
lint: | ||
@ go get -v golang.org/x/lint/golint | ||
@for file in $$(git ls-files '*.go' | grep -v '_workspace/'); do \ | ||
export output="$$(golint $${file} | grep -v 'type name will be used as docker.DockerInfo')"; \ | ||
[ -n "$${output}" ] && echo "$${output}" && export status=1; \ | ||
done; \ | ||
exit $${status:-0} | ||
|
||
vet: main.go | ||
go vet $< | ||
|
||
imports: main.go | ||
go get golang.org/x/tools/cmd/goimports && goimports -d $< | ||
.PHONY: vendor | ||
vendor: # Vendor go modules | ||
go mod vendor | ||
|
||
test: lint vet imports | ||
GO111MODULE=on go test -v ./... | ||
.PHONY: coverage | ||
coverage: ## Generates coverage report | ||
rm -f coverage.out | ||
go test -v ./... -coverpkg=./... -coverprofile=coverage.out | ||
|
||
vendor: | ||
GO111MODULE=on go mod vendor | ||
.PHONY: publish-coveralls | ||
publish-coveralls: setup ## Publish coverage results on coveralls | ||
goveralls -service=travis-ci -coverprofile=coverage.out | ||
|
||
coverage: | ||
rm -rf *.out | ||
go test -coverprofile=coverage.out | ||
for i in config util s3 db api compare auth; do \ | ||
go test -coverprofile=$$i.coverage.out github.com/camptocamp/terraboard/$$i; \ | ||
tail -n +2 $$i.coverage.out >> coverage.out; \ | ||
done | ||
.PHONY: clean | ||
clean: ## Remove binary if it exists | ||
rm -f $(NAME) | ||
|
||
clean: | ||
rm -f terraboard | ||
.PHONY: all | ||
all: lint test build coverage | ||
|
||
.PHONY: all lint vet imports test coverage clean | ||
.PHONY: help | ||
help: ## Displays this help | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters