mardi 27 septembre 2016

Integration tests in golang - how to test the link between the router and the http.Handlers?

I've been tinkering around with golang and I try to implement a little todo application which should grow with the time. My thoughts about the applications architecture are the following:

  • The main package sets up the server and integrates the "services/handler" of the other packages in it's router under the corresponding path prefixes.
  • Every "service" has its own handlers and routes them correctly

So I've started just with the main package and wrote some todo handlers. To test the API I've written some integration tests (request/response). Now, I've removed the todo logic from the main package into it's own. When I execute go test -cover it shows me just the coverage of the main.go, but not for the todo package. That leads me to the conclusion that each package has to test on it's own.

So I have not to test the API in the main package but the integration, that '/todos' ends up in the todo package and nothing more, is that right? How can I test that? And in the todo package I have to test:

  • The routing in the package
  • And with a response recorder the API implementation

Is that right too? So how can I test the routing on it's own? Is that possible?

Here is my git repository: http://ift.tt/2dcQdUr

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire