I began to write unit tests for my private project and ran into a weird problem that I have seen others comment on because of the inability to use fake HTTP requests for things like unit testing.
For particular App Engine operations, you pass the incoming HTTP request object to things like the Datastore. However, for unit tests, you have to create a fake HTTP request. Or so I thought.
This is the error that I get:
panic: appengine: NewContext passed an unknown http.Request [recovered]
panic: appengine: NewContext passed an unknown http.Request
(Note: There are some solutions to this problem already before this update like this elegant solution by Mark Mendel. But now with the update it’s a lot simpler.)
However, version 1.9.11 of the Go App Engine SDK brought some very convenient additions. I will show you that a fairly recent update allows you fix this problem easily.
This is part 2 of a series of posts that involve developing and publishing to Google’s App Engine with Go as the backend. In addition, it will exemplify how to take advantage of the App Engine’s new module system. This post will explore the actual development and local testing.
Google has moved to from having a single frontend (with optional backends) to this notion of modules in 2013. This is important as it stresses the importance of modularizing your code. Each module should have a specific purpose. If you architect your code that way, Google will take care scaling your app appropriately.
This post series won’t explore the “Version” aspect much. Possibly in a future post.
- This post will walk you through how to create two modules.
- We will call Module A (Our frontend).
- Module A will call Module B (The backend). Module B will produce an output and return it in the response body.
- Module A will display some other text with the output of Module B appended to it.
- This post will walk through modifying custom routing for the modules.
We should get something like this when we visit our frontend:
This is part 1 of a series of posts that involve developing and publishing to Google’s App Engine with Go as the backend. In addition, it will exemplify how to take advantage of the App Engine’s new module system. This post will run through setting up your existing Go environment to develop using Google App Engine.
Setup Installing Google Cloud SDK for Go This post assumes you already have Go setup.