From 5647bc983aab174545102a82eda53927d425c06d Mon Sep 17 00:00:00 2001 From: Pradeep Kumar Date: Tue, 24 May 2022 19:04:50 +0530 Subject: [PATCH] fix go test --- hack/tools.go | 1 + test/presubmit-tests.sh | 36 +++++++++++++++++++ .../hashicorp/go-plugin/process_posix.go | 1 - .../hashicorp/go-rootcerts/rootcerts_base.go | 1 - .../go-secure-stdlib/mlock/mlock_unavail.go | 1 - .../go-secure-stdlib/mlock/mlock_unix.go | 1 - .../hashicorp/go-sockaddr/ifaddrs.go | 3 +- .../go-sockaddr/route_info_android.go | 1 + .../hashicorp/go-sockaddr/route_info_bsd.go | 1 - .../go-sockaddr/route_info_default.go | 1 - .../hashicorp/go-sockaddr/route_info_linux.go | 1 - .../github.com/hashicorp/go-uuid/uuid.go | 3 +- .../golang-lru/simplelru/lru_interface.go | 4 +-- .../hashicorp/vault/sdk/version/cgo.go | 1 - 14 files changed, 44 insertions(+), 12 deletions(-) diff --git a/hack/tools.go b/hack/tools.go index 7127604d1..3906f6e28 100644 --- a/hack/tools.go +++ b/hack/tools.go @@ -1,3 +1,4 @@ +//go:build tools // +build tools package tools diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh index 71813f502..c5714a8ef 100755 --- a/test/presubmit-tests.sh +++ b/test/presubmit-tests.sh @@ -94,6 +94,42 @@ function post_build_tests() { check_yaml_lint } +function unit_tests() { + make test +} + +function build_tests() { + local failed=0 + # Check go code style with gofmt; exclude vendor/ files + subheader "Checking go code style with gofmt" + gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*')) + if [[ -n "$gofmt_out" ]]; then + failed=1 + fi + echo "$gofmt_out" + # Perform markdown build checks first + markdown_build_tests || failed=1 + # Check yaml using yamllint + yaml_build_tests || failed=1 + # For documentation PRs, just check the md files + (( IS_DOCUMENTATION_PR )) && return ${failed} + # Skip build test if there is no go code + local go_pkg_dirs="$(go list ./...)" + [[ -z "${go_pkg_dirs}" ]] && return ${failed} + # Ensure all the code builds + subheader "Checking that go code builds" + # only diff in default_build_test_runner and build_test + go build -v ./cmd... || failed=1 + if [[ -f ./hack/verify-codegen.sh ]]; then + subheader "Checking autogenerated code is up-to-date" + ./hack/verify-codegen.sh || failed=1 + fi + # Check that we don't have any forbidden licenses in our images. + subheader "Checking for forbidden licenses" + check_licenses ${go_pkg_dirs} || failed=1 + return ${failed} +} + # We use the default build, unit and integration test runners. if [[ "$1" == "--build-cross-tests" ]]; then make cross diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-plugin/process_posix.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-plugin/process_posix.go index 185957f8d..70ba546bf 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-plugin/process_posix.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-plugin/process_posix.go @@ -1,4 +1,3 @@ -//go:build !windows // +build !windows package plugin diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-rootcerts/rootcerts_base.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-rootcerts/rootcerts_base.go index ba58717f5..66b1472c4 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-rootcerts/rootcerts_base.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-rootcerts/rootcerts_base.go @@ -1,4 +1,3 @@ -//go:build !darwin // +build !darwin package rootcerts diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unavail.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unavail.go index ca6887e91..941eb2d7b 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unavail.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unavail.go @@ -1,4 +1,3 @@ -//go:build darwin || nacl || netbsd || plan9 || windows // +build darwin nacl netbsd plan9 windows package mlock diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unix.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unix.go index 1a774bea5..af0a69d48 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unix.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-secure-stdlib/mlock/mlock_unix.go @@ -1,4 +1,3 @@ -//go:build dragonfly || freebsd || linux || openbsd || solaris // +build dragonfly freebsd linux openbsd solaris package mlock diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/ifaddrs.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/ifaddrs.go index d58cb50af..80f61bef6 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/ifaddrs.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/ifaddrs.go @@ -1214,7 +1214,7 @@ func parseDefaultIfNameFromIPCmd(routeOut string) (string, error) { // Android. func parseDefaultIfNameFromIPCmdAndroid(routeOut string) (string, error) { parsedLines := parseIfNameFromIPCmd(routeOut) - if len(parsedLines) > 0 { + if (len(parsedLines) > 0) { ifName := strings.TrimSpace(parsedLines[0][4]) return ifName, nil } @@ -1222,6 +1222,7 @@ func parseDefaultIfNameFromIPCmdAndroid(routeOut string) (string, error) { return "", errors.New("No default interface found") } + // parseIfNameFromIPCmd parses interfaces from ip(8) for // Linux. func parseIfNameFromIPCmd(routeOut string) [][]string { diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_android.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_android.go index 6f484cc44..9885915a6 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_android.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_android.go @@ -25,6 +25,7 @@ func (ri routeInfo) GetDefaultInterfaceName() (string, error) { return "", err } + var ifName string if ifName, err = parseDefaultIfNameFromIPCmdAndroid(string(out)); err != nil { return "", errors.New("No default interface found") diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_bsd.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_bsd.go index 89308cf7c..705757abc 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_bsd.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_bsd.go @@ -1,4 +1,3 @@ -//go:build darwin || dragonfly || freebsd || netbsd || openbsd // +build darwin dragonfly freebsd netbsd openbsd package sockaddr diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_default.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_default.go index fe291fb0d..d1b009f65 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_default.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_default.go @@ -1,4 +1,3 @@ -//go:build android || nacl || plan9 // +build android nacl plan9 package sockaddr diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_linux.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_linux.go index 1b2720488..b62ce6ecb 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_linux.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-sockaddr/route_info_linux.go @@ -1,4 +1,3 @@ -//go:build !android // +build !android package sockaddr diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-uuid/uuid.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-uuid/uuid.go index 6424c8465..0c10c4e9f 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/go-uuid/uuid.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/go-uuid/uuid.go @@ -24,6 +24,7 @@ func GenerateRandomBytesWithReader(size int, reader io.Reader) ([]byte, error) { return buf, nil } + const uuidLen = 16 // GenerateUUID is used to generate a random UUID @@ -57,7 +58,7 @@ func FormatUUID(buf []byte) (string, error) { } func ParseUUID(uuid string) ([]byte, error) { - if len(uuid) != 2*uuidLen+4 { + if len(uuid) != 2 * uuidLen + 4 { return nil, fmt.Errorf("uuid string is wrong length") } diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/golang-lru/simplelru/lru_interface.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/golang-lru/simplelru/lru_interface.go index a0b97e3f7..92d70934d 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/golang-lru/simplelru/lru_interface.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/golang-lru/simplelru/lru_interface.go @@ -34,6 +34,6 @@ type LRUCache interface { // Clears all cache entries. Purge() - // Resizes cache, returning number evicted - Resize(int) int + // Resizes cache, returning number evicted + Resize(int) int } diff --git a/third_party/VENDOR-LICENSE/github.com/hashicorp/vault/sdk/version/cgo.go b/third_party/VENDOR-LICENSE/github.com/hashicorp/vault/sdk/version/cgo.go index 91d3dd97b..2ed493a1f 100644 --- a/third_party/VENDOR-LICENSE/github.com/hashicorp/vault/sdk/version/cgo.go +++ b/third_party/VENDOR-LICENSE/github.com/hashicorp/vault/sdk/version/cgo.go @@ -1,4 +1,3 @@ -//go:build cgo // +build cgo package version