Pretend you're working with your friend to create some blog software. The idea is an author will write their posts in markdown, with some metadat

Reading files - Learn Go with tests

submited by
Style Pass
2021-06-11 12:30:09

Pretend you're working with your friend to create some blog software. The idea is an author will write their posts in markdown, with some metadata at the top of the file. On startup, the web server will read a folder to create some Post s, and then a separate NewHandler function will use those Post s as a datasource for the blog's webserver.

This requires us to break up our work, but we should be careful not to fall into the trap of taking a "bottom up" approach.

We should not trust our over-active imaginations when we start work. We could be tempted into making some kind of abstraction that is only validated once we stick everything together, such as some kind of BlogPostFileParser .

Instead, our approach should strive to be as close to delivering real consumer value as quickly as possible (often called a "happy path"). Once we have delivered a small amount of consumer value end-to-end, further iteration of the rest of the requirements is usually straightforward.

Write the test we want to see . Think about how we'd like to use the code we're going to write from a consumer's point of view.

Leave a Comment