Post about Go development.
Post about Go development.
Table-driven tests are a cornerstone of good unit testing in any language, Go included. They allow us to group related test cases, making it simple to cover numerous inputs, outputs, and edge cases in a concise and readable way. When you have functionality that needs to be exercised in a variety of ways, a table test is often the right tool for the job.
When writing a Go test, don’t just assert that an error occurred - assert that the error you have is the one you expect.
In the early days of the web, circa 1995 or so, it was common for the forms on websites to return a single error on submission, identifying only the first field that needed attention. This resulted frequent failed submissions as users would only be able to fix one thing at a time. To say that this made for a laborious and frustrating process would be a massive understatement.
When managing errors in your code, help out your future self (and anyone else who will be supporting your code in the future) by doing more than the simplest possible thing.
One of the best ways to disappoint someone is to break a promise - and this applies both to the software we write and the applications we use as well.