0

It seems go test ./... runs each test file using the file's directory as the root dir.

E.g., if a test is my_project/service/service_test.go, then it is run with root dir set to my_project/service/.

This causes trouble because I need to load config files during the test, which are located at my_project/config.

What I am doing now is setting an env variable WORK_DIR, setting it to my_project, and using it to load the config files.

Is there a feature in Go that allows setting the work dir for tests?

stackoverflower
  • 3,885
  • 10
  • 47
  • 71
  • Please note I am not writing unit tests, but acceptance tests, which are for testing the service after it as been deployed. – stackoverflower Oct 12 '17 at 12:55
  • 1
    Possible duplicate of [How to Specify Path of Template for App Engine with Go for Unit Testing?](https://stackoverflow.com/questions/38320920/how-to-specify-path-of-template-for-app-engine-with-go-for-unit-testing/38322844#38322844); and [how to reference a relative file from code and tests](https://stackoverflow.com/questions/31059023/how-to-reference-a-relative-file-from-code-and-tests/31059125#31059125). – icza Oct 12 '17 at 12:56
  • 1
    How do you test a service with `go test` after it has been deployed? That doesn't make sense to me. Don't you deploy the compiled binary? – Peter Oct 12 '17 at 13:07
  • I closed this as duplicate – stackoverflower Oct 12 '17 at 14:47

0 Answers0