Skip to content

Commit

Permalink
fix go test
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepitm12 authored and vdemeester committed Jun 1, 2022
1 parent 9641d28 commit 5647bc9
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tools
// +build tools

package tools
Expand Down
36 changes: 36 additions & 0 deletions test/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build !windows
// +build !windows

package plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build !darwin
// +build !darwin

package rootcerts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build darwin || nacl || netbsd || plan9 || windows
// +build darwin nacl netbsd plan9 windows

package mlock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build dragonfly || freebsd || linux || openbsd || solaris
// +build dragonfly freebsd linux openbsd solaris

package mlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,14 +1214,15 @@ 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
}

return "", errors.New("No default interface found")
}


// parseIfNameFromIPCmd parses interfaces from ip(8) for
// Linux.
func parseIfNameFromIPCmd(routeOut string) [][]string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
// +build darwin dragonfly freebsd netbsd openbsd

package sockaddr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build android || nacl || plan9
// +build android nacl plan9

package sockaddr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build !android
// +build !android

package sockaddr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//go:build cgo
// +build cgo

package version
Expand Down

0 comments on commit 5647bc9

Please sign in to comment.