I have to run Go tests for database interactions. Database Schema is in a .sql file. I have a folder A which has package main and I have 3 folders B, C and D inside A which have package B, C and D respectively. B,C,D have test files in them but A does not have any tests. I want a way so that I just do a
go test ./...
from A and all my tests run after sourcing schema into mysql.
I tried making a main_test.go file in A and placing a TestMain function there. But it was not working.
you can use init function on main_test.go
package main
func init(){
// load and execute your db schema here.
}
https://golang.org/ref/spec#Package_initialization
the init()
on main package will be executed on package initialization