News for hackers. Stuff that matters.
Re:The Myth of Code Coverage by jrockway on Friday December 04, 2020 @05:14PM (#25308935)
I prefer to test everything. The parts you don't test are the parts that break.

For example, here's a case where I incremented the wrong metric:

https://github.com/jrockway/alertmanager-status/commit/fccae...

I noticed the bug when I went to look at a dashboard with that metric on it, and noticed it had the wrong name. If go's Prometheus library had an easy way to run "metric.CurrentValue()", I would have tested it... but it didn't, so I didn't. And then had to patch it, release it, and update all my servers. Writing the test (with that API) would have taken less than a second. Finding the bug in production and fixing it took an hour.

(That codebase has 100% line coverage, but of course, I know that 100% test coverage is a meaningless metric. That the code ran is a prerequisite to the program behaving correctly, but it also has to do the right thing.)

Re:The Myth of Code Coverage by morelisp on Friday December 04, 2020 @06:37PM (#25309785)
> If go's Prometheus library had an easy way to run "metric.CurrentValue()"...

A small tip for the future: https://pkg.go.dev/github.com/prometheus/client_golang/prome....

Re:The Myth of Code Coverage by jrockway on Friday December 04, 2020 @06:55PM (#25309961)
Thanks! I've seen that before, but didn't realize that ToFloat64() was what I was looking for.
Re:The Myth of Code Coverage by tcbasche on Saturday December 05, 2020 @04:10AM (#25312996)
Arguably you should be testing behaviour rather than getters and setters. If a codepath requires a name formatted correctly, then that forms the basis of a test and an assertion. Otherwise you're introducing fragility by coupling your 'under the hood' stuff with your 'API' (so to speak).