When using the local development server, the port for my default service always defaults to 8080. However, when I use aetest
, the port number always changes. The command used to start the local server when unit testing specifies --port=0
. However, since this is in the app engine package, I do not want to modify it. I also can't specify the port number manually since tests are run using go test
and not dev_appserver.py
.
What I need
The code I am testing requires a particular response from a different microservice to continue execution successfully. To keep testing to this microservice, I am trying to set up a fake endpoint to provide me with the response I need.
Sample of code being tested
func Sample(c *gin.Context) {
...
url := os.Getenv("some_service") + "/some-endpoint"
req, err := http.NewRequest("POST", url, r.Body)
if err != nil {
// error handling
}
...
}
I need the host of the current service being tested to be able to set dummy environment variables for another microservice it interacts with. The host url should be the url of the service currently undergoing tests. This way I can use factory responses since I am not testing the other services in this set of tests.
What I've Tried
- Using
appengine.DefaultVersionHostname()
, however this returns an empty string - Using the http request I create to get the url from that, however it does not include the host as needed (just the path)
Question
Is there any way to obtain the host for the local development server when running unit tests in GAE? Or, is there a way to specify the port number for app engine tests?