I got a structure of my project that looks pretty like this:
project/
api/
api.go
config/
config.go
config.toml
tests/
api_test.go
main.go
So, whenever I initialize config package I'm trying to read config file using relative path: config/config.toml
.
This works fine as soon as I run my program: go run main.go
The problem appears when I try to run my tests: go test project/tests
. My config package cannot find file config/config.toml
because current work directory is not project/
as in first case but project/tests/
.
Is there any convenient way to access config file from both run
and test
?