3 ms·
How I write Go HTTP services after 7 years
- stockkid 8y agoVery nice. > By calling ServeHTTP on the server, we are testing the entire stack including routing and middleware, etc. You can of course call the handler methods directly if you want to avoid this What is the trade-off between the two? Does it make the tests significantly slower to test the entire stack rather than just a handler?
- carc1n0gen 8y agoI usually do both. I like having unit tests that test individual function that describe functionality. But I also like to have tests that ensure everything works as intended ones you throw everything together.
- stockkid 8y agoTo be clear, you test individual functions handler uses, and to test the handlers themselves, you opt to test the whole stack as described in the article?
- carc1n0gen 8y agoI test the whole stack to ensure things work as intended when all put together. But I also write very isolated unit tests. I usually have them in separate test suites so I can choose which ones to run
- vonseel 8y ago7 years is a long-time in Golangland.
- vonseel 8y agoNot part of the post but can't help and laugh at the company's marketing snipped below. Buzz-worthy! "What is this Machine Box that I keep hearing all this amazing stuff about? Machine Learning in Docker containers for Kubernetes — implement some ML today, without having to learn all that Tensorflow stuff."