Skip to content

testing/slogtest: TestHandler passing tests that should fail #67605

@mmTristan

Description

@mmTristan

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/usr/.cache/go-build'
GOENV='/home/usr/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/usr/go/pkg/mod'
GONOPROXY='gitlab.com/*,github.com/*'
GONOSUMDB='gitlab.com/*,github.com/*'
GOOS='linux'
GOPATH='/home/usr/go'
GOPRIVATE='gitlab.com/*,github.com/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/mnt/c/Users/usr/Documents/git/glmrx-svr-dev/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3234934194=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I was trying to implement slog test handlers based off of the example code. But when checking for the expected errors with parsing empty maps, it still passes the test.
Here is the go playground of the error (or lack of)

It looks like in the source code at line 219 it calls the test again without checking for the length of the returned slice. So when a 0 length slice is returned the tests aren't run.

There is a workaround where you put the results back into the channel, but that is easy to overloook. workaround go playground
The code should be updated to check for the lengths again, or use the results from the length checking test call.

What did you see happen?

Ran the test and got this response.

test errors: <nil>

What did you expect to see?

Expected to get a list of missing keys in the returned maps.

test errors: A lot of errors for each map key

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions