How to turn off test caching for golang!
When testing Golang projects you'll notice that test results are cached for as long as their corresponding source files remain unchanged. This is generally advantageous, unless your test cases behave differently depending on the environment that they are running in, just like our
pg_timetable scheduler depends on a PostgreSQL
database.
Before Go 1.12
the known solution was to use the GOCACHE=off
environment variable, e.g.
$ GOCACHE=off go test ./internal/pgengine -v
However starting from Go 1.12
this leads to the error:
$ GOCACHE=off go test ./internal/pgengine -v
build cache is disabled by GOCACHE=off, but required as of Go 1.12
As a solution one may clear the build cache explicitly before running tests:
$ go clean -cache
Or only clean the test cache:
$ go clean -testcache
Another approach is to use environmental variables:
$ GOFLAGS="-count=1" go test ./internal/pgengine -v