maxbrunsfeld / counterfeiter

A tool for generating self-contained, type-safe test doubles in go
MIT License
931 stars 90 forks source link

Cannot regenerate fakes if they are relied upon and deleted - go1.19.10 #246

Open waciumawanjohi opened 1 year ago

waciumawanjohi commented 1 year ago

Go Version

1.19.10

Reproduction steps

# Clone an open source project using counterfeiter for testing
git clone https://github.com/vmware-tanzu/cartographer.git
cd cartographer

# Install go 1.19.10
go install golang.org/dl/go1.19.10@latest
go1.19.10 download

# Delete previously generated fakes
rm -rf pkg/repository/repositoryfakes/

# Run go generate
go1.19.10 generate ./pkg/repository

Expected result

Deleted files are recreated. Output:

Writing `FakeLogger` to `repositoryfakes/fake_logger.go`... Done
Writing `FakeRepoCache` to `repositoryfakes/fake_repo_cache.go`... Done
Writing `FakeClient` to `repositoryfakes/fake_client.go`... Done
Writing `FakeRepository` to `repositoryfakes/fake_repository.go`... Done

Observed result

Command errors. Output:

Writing `FakeLogger` to `repositoryfakes/fake_logger.go`... 
err: exit status 1: stderr: go build github.com/vmware-tanzu/cartographer/pkg/repository/repositoryfakes: cache_test.go:23:2: no required module provides package github.com/vmware-tanzu/cartographer/pkg/repository/repositoryfakes; to add it:
        go get github.com/vmware-tanzu/cartographer/pkg/repository/repositoryfakes

exit status 1
pkg/repository/repository.go:37: running "go": exit status 1

Comments

This workflow works when using go 1.19.9

You can cleanup the go downloads above by running

rm -rf $(go1.19.10 env GOROOT)
rm $(which go1.19.10)
vmware-cartographer commented 1 year ago

This problem is not observed when using go 1.20.5.

Workaround

Bump go to 1.20