I need to add: In the post the reproducer test is of course to short, so the test show that it fails all the time. But that triggers the problem anyway. Better would be this:
func TestHelloer(t *testing.T) { want := "Hello, world!" got := Helloer() if got != want { t.Errorf("Helloer() = %v, want %v", got, want) } } Also, the output of the go test call has a inidication why it has exit status 1: $ go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... -covermode count example.com/m: open /tmp/go-build1679138031/b002/covmeta.f6e4431d5ec1fd71f02b3ce4e56eb691a86525173d917007425576a7d9db7c72: no such file or directory === RUN TestHelloer helloer_test.go:8: Helloer() = Hello, world!, want Hello, world! --- FAIL: TestHelloer (0.00s) FAIL coverage: 100.0% of statements in ./internal/... FAIL example.com/m/internal 0.003s Also this happens with the Alpine based image, but also for the Debian based image as well. On Thursday, February 8, 2024 at 12:43:32 AM UTC+1 Martin wrote: > I am using the new `golang:1.22.0-alpine3.19` Alpine image to build and > test a Golang 1.22.0 application. The test uses coverage like that `go > test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... > -covermode count`. The test command seems to work fine, but the exit status > is 1. The created coverage.out seems also fine, as I could use go tool > cover with it, see below. > > Golang version: 1.22.0 > Container Image: golang:1.22.0-alpine3.19 > > Reproducer: > > main.go: > package main > > import ( > "example.com/m/internal" > "fmt" > ) > > func main() { > fmt.Println(internal.Helloer()) > } > > > internal/helloer.go: > package internal > > func Helloer() string { > return "Hello, world!" > } > > internal/helloer_test.go: > package internal > > import "testing" > > func TestHelloer(t *testing.T) { > want := "Hello, world!" > got := Helloer() > t.Errorf("Helloer() = %v, want %v", got, want) > } > > go.mod: > module example.com/m > > go 1.22 > > Shell commands for testing: > > apk add --no-cache build-base > go test -v ./... -coverprofile=coverage.out -coverpkg=./internal/... > -covermode count || echo "flaky:$?" > go tool cover -html=coverage.out -o coverage.html > go tool cover -func=coverage.out > > > Is it a bug or exepected behaviour? > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c2fcc039-075e-4208-879e-5fdc11a0a18dn%40googlegroups.com.