Remove faulty error type checks.
These type checks were not doing anything - which was surfaced by a `go vet` run on the more recent Go version. errors.As with the second argument of type *error will always return true. I played a little bit with trying to get a working typecheck in this test, but it didn't really work because of issues with the fork github.com/Clever/syslogparser. Since that parser didn't update self-references to point to itself instead of the upstream, our errors returned by this are already not really working correctly - sometimes they are Clever/syslogparser.ParseError and sometimes jeromer/syslogparser.ParseError. Fixing the underlying problem is out of scope for right now.
This commit is contained in:
parent
e734611a60
commit
de490c45ab
2 changed files with 43 additions and 14 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
package decode
|
package decode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -222,7 +221,6 @@ func TestSyslogDecoding(t *testing.T) {
|
||||||
fields, err := FieldsFromSyslog(spec.Input)
|
fields, err := FieldsFromSyslog(spec.Input)
|
||||||
if spec.ExpectedError != nil {
|
if spec.ExpectedError != nil {
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(errors.As(err, &spec.ExpectedError))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
@ -547,7 +545,6 @@ select sleep(2);`,
|
||||||
fields, err := ParseAndEnhance(spec.Line, "deploy-env")
|
fields, err := ParseAndEnhance(spec.Line, "deploy-env")
|
||||||
if spec.ExpectedError != nil {
|
if spec.ExpectedError != nil {
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(errors.As(err, &spec.ExpectedError))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
@ -557,7 +554,6 @@ select sleep(2);`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainerMeta(t *testing.T) {
|
func TestGetContainerMeta(t *testing.T) {
|
||||||
|
|
||||||
type containerMetaSpec struct {
|
type containerMetaSpec struct {
|
||||||
description string
|
description string
|
||||||
input map[string]interface{}
|
input map[string]interface{}
|
||||||
|
|
|
||||||
53
golang.mk
53
golang.mk
|
|
@ -1,7 +1,7 @@
|
||||||
# This is the default Clever Golang Makefile.
|
# This is the default Clever Golang Makefile.
|
||||||
# It is stored in the dev-handbook repo, github.com/Clever/dev-handbook
|
# It is stored in the dev-handbook repo, github.com/Clever/dev-handbook
|
||||||
# Please do not alter this file directly.
|
# Please do not alter this file directly.
|
||||||
GOLANG_MK_VERSION := 1.0.0
|
GOLANG_MK_VERSION := 1.1.0
|
||||||
|
|
||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
|
SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
@ -11,7 +11,7 @@ SYSTEM := $(shell uname -a | cut -d" " -f1 | tr '[:upper:]' '[:lower:]')
|
||||||
export TZ=UTC
|
export TZ=UTC
|
||||||
|
|
||||||
# go build flags for use across all commands which accept them
|
# go build flags for use across all commands which accept them
|
||||||
GO_BUILD_FLAGS := "-mod=vendor"
|
export GOFLAGS := -mod=vendor $(GOFLAGS)
|
||||||
|
|
||||||
# if the gopath includes several directories, use only the first
|
# if the gopath includes several directories, use only the first
|
||||||
GOPATH=$(shell echo $$GOPATH | cut -d: -f1)
|
GOPATH=$(shell echo $$GOPATH | cut -d: -f1)
|
||||||
|
|
@ -39,7 +39,7 @@ endef
|
||||||
# so we're defended against it breaking or changing in the future.
|
# so we're defended against it breaking or changing in the future.
|
||||||
FGT := $(GOPATH)/bin/fgt
|
FGT := $(GOPATH)/bin/fgt
|
||||||
$(FGT):
|
$(FGT):
|
||||||
go get github.com/GeertJohan/fgt@262f7b11eec07dc7b147c44641236f3212fee89d
|
go install -mod=readonly github.com/GeertJohan/fgt@262f7b11eec07dc7b147c44641236f3212fee89d
|
||||||
|
|
||||||
golang-ensure-curl-installed:
|
golang-ensure-curl-installed:
|
||||||
@command -v curl >/dev/null 2>&1 || { echo >&2 "curl not installed. Please install curl."; exit 1; }
|
@command -v curl >/dev/null 2>&1 || { echo >&2 "curl not installed. Please install curl."; exit 1; }
|
||||||
|
|
@ -49,7 +49,7 @@ golang-ensure-curl-installed:
|
||||||
# previously passing tests start failing without changing our code.
|
# previously passing tests start failing without changing our code.
|
||||||
GOLINT := $(GOPATH)/bin/golint
|
GOLINT := $(GOPATH)/bin/golint
|
||||||
$(GOLINT):
|
$(GOLINT):
|
||||||
go get golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626
|
go install -mod=readonly golang.org/x/lint/golint@738671d3881b9731cc63024d5d88cf28db875626
|
||||||
|
|
||||||
# golang-fmt-deps requires the FGT tool for checking output
|
# golang-fmt-deps requires the FGT tool for checking output
|
||||||
golang-fmt-deps: $(FGT)
|
golang-fmt-deps: $(FGT)
|
||||||
|
|
@ -89,7 +89,7 @@ golang-test-deps:
|
||||||
# arg1: pkg path
|
# arg1: pkg path
|
||||||
define golang-test
|
define golang-test
|
||||||
@echo "TESTING $(1)..."
|
@echo "TESTING $(1)..."
|
||||||
@go test $(GO_BUILD_FLAGS) -v $(1)
|
@go test -v $(1)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# golang-test-strict-deps is here for consistency
|
# golang-test-strict-deps is here for consistency
|
||||||
|
|
@ -99,7 +99,22 @@ golang-test-strict-deps:
|
||||||
# arg1: pkg path
|
# arg1: pkg path
|
||||||
define golang-test-strict
|
define golang-test-strict
|
||||||
@echo "TESTING $(1)..."
|
@echo "TESTING $(1)..."
|
||||||
@go test -v $(GO_BUILD_FLAGS) -race $(1)
|
@go test -v -race $(1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
# golang-test-strict-cover-deps is here for consistency
|
||||||
|
golang-test-strict-cover-deps:
|
||||||
|
|
||||||
|
# golang-test-strict-cover uses the Go toolchain to run all tests in the pkg with the race and cover flag.
|
||||||
|
# appends coverage results to coverage.txt
|
||||||
|
# arg1: pkg path
|
||||||
|
define golang-test-strict-cover
|
||||||
|
@echo "TESTING $(1)..."
|
||||||
|
@go test -v -race -cover -coverprofile=profile.tmp -covermode=atomic $(1)
|
||||||
|
@if [ -f profile.tmp ]; then \
|
||||||
|
cat profile.tmp | tail -n +2 >> coverage.txt; \
|
||||||
|
rm profile.tmp; \
|
||||||
|
fi;
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# golang-vet-deps is here for consistency
|
# golang-vet-deps is here for consistency
|
||||||
|
|
@ -109,7 +124,7 @@ golang-vet-deps:
|
||||||
# arg1: pkg path
|
# arg1: pkg path
|
||||||
define golang-vet
|
define golang-vet
|
||||||
@echo "VETTING $(1)..."
|
@echo "VETTING $(1)..."
|
||||||
@go vet $(GO_BUILD_FLAGS) $(1)
|
@go vet $(1)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# golang-test-all-deps installs all dependencies needed for different test cases.
|
# golang-test-all-deps installs all dependencies needed for different test cases.
|
||||||
|
|
@ -137,19 +152,37 @@ $(call golang-vet,$(1))
|
||||||
$(call golang-test-strict,$(1))
|
$(call golang-test-strict,$(1))
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
# golang-test-all-strict-cover-deps: installs all dependencies needed for different test cases.
|
||||||
|
golang-test-all-strict-cover-deps: golang-fmt-deps golang-lint-deps-strict golang-test-strict-cover-deps golang-vet-deps
|
||||||
|
|
||||||
|
# golang-test-all-strict-cover calls fmt, lint, vet and test on the specified pkg with strict and cover
|
||||||
|
# requirements that no errors are thrown while linting.
|
||||||
|
# arg1: pkg path
|
||||||
|
define golang-test-all-strict-cover
|
||||||
|
$(call golang-fmt,$(1))
|
||||||
|
$(call golang-lint-strict,$(1))
|
||||||
|
$(call golang-vet,$(1))
|
||||||
|
$(call golang-test-strict-cover,$(1))
|
||||||
|
endef
|
||||||
|
|
||||||
# golang-build: builds a golang binary. ensures CGO build is done during CI. This is needed to make a binary that works with a Docker alpine image.
|
# golang-build: builds a golang binary. ensures CGO build is done during CI. This is needed to make a binary that works with a Docker alpine image.
|
||||||
# arg1: pkg path
|
# arg1: pkg path
|
||||||
# arg2: executable name
|
# arg2: executable name
|
||||||
define golang-build
|
define golang-build
|
||||||
@echo "BUILDING..."
|
@echo "BUILDING $(2)..."
|
||||||
@if [ -z "$$CI" ]; then \
|
@if [ -z "$$CI" ]; then \
|
||||||
go build $(GO_BUILD_FLAGS) -o bin/$(2) $(1); \
|
go build -o bin/$(2) $(1); \
|
||||||
else \
|
else \
|
||||||
echo "-> Building CGO binary"; \
|
echo "-> Building CGO binary"; \
|
||||||
CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -installsuffix cgo -o bin/$(2) $(1); \
|
CGO_ENABLED=0 go build -installsuffix cgo -o bin/$(2) $(1); \
|
||||||
fi;
|
fi;
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
# golang-setup-coverage: set up the coverage file
|
||||||
|
define golang-setup-coverage:
|
||||||
|
@echo "mode: atomic" > coverage.txt
|
||||||
|
endef
|
||||||
|
|
||||||
# golang-update-makefile downloads latest version of golang.mk
|
# golang-update-makefile downloads latest version of golang.mk
|
||||||
golang-update-makefile:
|
golang-update-makefile:
|
||||||
@wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2>/dev/null
|
@wget https://raw.githubusercontent.com/Clever/dev-handbook/master/make/golang-v1.mk -O /tmp/golang.mk 2>/dev/null
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue