A go program connects to a database using a connection string. Currently that connection string is stored in an environment variable.
My challenge is to write a an automated test that exercises the program against a test database.
I thought I would set the connection string environment variable in the init() function of the test, but the main program's init() function is called before the test init(), so this does not work.
The workaround seems to be to default the connection string to the test database. If no environment variable is defined, use test; if it is defined (production), then use that instead.
Is there an alternative? Is there a better approach?