Run go tests for multiple modules

I am using go to test some terraform code and am new to the language. What I am trying to do is run tests on multiple go modules which test out individual terraform modules. Currently my test modules are structured like this:

To run the individual tests, my current solution (probably naive) is to go to the individual test module and run:
go mod init
go mod tidy
go test -v <TEST_MODULE.GO FILE>

Was there any way to run the tests located in the individual modules together instead of running the tests separately. Currently I am utilizing a script to run them all together but there is no good way to fail fast in that scenario.
Since I am very new to go I probably did not do this the right way and any suggestions would be very helpful.

I’m not aware of a native go way, but failfast should work pretty well…

set -e should do the job if I recall correctly. Might be set -x as well… Usually I use those 2 together and don’t need to care which bubbles up failure and which one dumps the commands…

Currently if any of my tests fail, it still sends the zero status code. Do I need to modify the go test code exit with a non-zero status code if it fails?

Figured it out. Just have to have a go mod file in the root directory. If go mod initdoes not work, just make a go.mod file with lines:
module <module name. Could be link to git project>
go <version>

And then I ran the step:
go mod tidy
go test [flags] ./...
May not be the right way, but it works and hope it helps anyone.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.