mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
Enforce go lint check and fix several lint issues (#570)
This fix updates the Makefile to add the `go lint` check for the build. This fix also fixes several go lint issues. NOTE: This fix does not enforce `go lint` (suggestion only). This fix also ignores the `go lint` error: ``` middleware/middleware.go:72:1: context.Context should be the first parameter of a function ``` as it requires too many changes in API. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
19
Makefile
19
Makefile
@@ -7,23 +7,27 @@ all: coredns
|
|||||||
# Phony this to ensure we always build the binary.
|
# Phony this to ensure we always build the binary.
|
||||||
# TODO: Add .go file dependencies.
|
# TODO: Add .go file dependencies.
|
||||||
.PHONY: coredns
|
.PHONY: coredns
|
||||||
coredns: deps core/zmiddleware.go core/dnsserver/zdirectives.go
|
coredns: check core/zmiddleware.go core/dnsserver/zdirectives.go
|
||||||
go build $(BUILD_VERBOSE) -ldflags="-s -w"
|
go build $(BUILD_VERBOSE) -ldflags="-s -w"
|
||||||
|
|
||||||
.PHONY: deps
|
.PHONY: deps
|
||||||
deps: fmt
|
deps:
|
||||||
go get ${BUILD_VERBOSE}
|
go get ${BUILD_VERBOSE}
|
||||||
|
go get -u github.com/golang/lint/golint
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check: fmt deps
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: deps
|
test: check
|
||||||
go test -race $(TEST_VERBOSE) ./test ./middleware/...
|
go test -race $(TEST_VERBOSE) ./test ./middleware/...
|
||||||
|
|
||||||
.PHONY: testk8s
|
.PHONY: testk8s
|
||||||
testk8s: deps
|
testk8s: check
|
||||||
go test -race $(TEST_VERBOSE) -tags=k8s -run 'TestKubernetes' ./test ./middleware/kubernetes/...
|
go test -race $(TEST_VERBOSE) -tags=k8s -run 'TestKubernetes' ./test ./middleware/kubernetes/...
|
||||||
|
|
||||||
.PHONY: coverage
|
.PHONY: coverage
|
||||||
coverage: deps
|
coverage: check
|
||||||
set -e -x
|
set -e -x
|
||||||
echo "" > coverage.txt
|
echo "" > coverage.txt
|
||||||
for d in `go list ./... | grep -v vendor`; do \
|
for d in `go list ./... | grep -v vendor`; do \
|
||||||
@@ -52,6 +56,11 @@ fmt:
|
|||||||
@test -z "$$(gofmt -s -l . | grep -v vendor/ | tee /dev/stderr)" || \
|
@test -z "$$(gofmt -s -l . | grep -v vendor/ | tee /dev/stderr)" || \
|
||||||
(echo "please format Go code with 'gofmt -s -w'" && false)
|
(echo "please format Go code with 'gofmt -s -w'" && false)
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint: deps
|
||||||
|
## run go lint, suggestion only (not enforced)
|
||||||
|
@test -z "$$(golint ./... | grep -v vendor/ | grep -v ".pb.go:" | grep -vE "context\.Context should be the first parameter of a function" | tee /dev/stderr)"
|
||||||
|
|
||||||
.PHONY: distclean
|
.PHONY: distclean
|
||||||
distclean: clean
|
distclean: clean
|
||||||
# Clean all dependencies and build artifacts
|
# Clean all dependencies and build artifacts
|
||||||
|
|||||||
@@ -155,10 +155,10 @@ func (s *Server) Address() string { return s.Addr }
|
|||||||
// defined in the request so that the correct zone
|
// defined in the request so that the correct zone
|
||||||
// (configuration and middleware stack) will handle the request.
|
// (configuration and middleware stack) will handle the request.
|
||||||
func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
s.ServeDNSWithContext(context.Background(), w, r)
|
s.serveDNSWithContext(context.Background(), w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ServeDNSWithContext(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) {
|
func (s *Server) serveDNSWithContext(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) {
|
||||||
defer func() {
|
defer func() {
|
||||||
// In case the user doesn't enable error middleware, we still
|
// In case the user doesn't enable error middleware, we still
|
||||||
// need to make sure that we stay alive up here
|
// need to make sure that we stay alive up here
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ import (
|
|||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateTestTrace creates a trace middleware to be used in tests
|
// createTestTrace creates a trace middleware to be used in tests
|
||||||
func CreateTestTrace(config string) (*caddy.Controller, *trace, error) {
|
func createTestTrace(config string) (*caddy.Controller, *trace, error) {
|
||||||
c := caddy.NewTestController("dns", config)
|
c := caddy.NewTestController("dns", config)
|
||||||
m, err := traceParse(c)
|
m, err := traceParse(c)
|
||||||
return c, m, err
|
return c, m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrace(t *testing.T) {
|
func TestTrace(t *testing.T) {
|
||||||
_, m, err := CreateTestTrace(`trace`)
|
_, m, err := createTestTrace(`trace`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error parsing test input: %s", err)
|
t.Errorf("Error parsing test input: %s", err)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user