diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2017-03-10 13:56:08 +0300 |
---|---|---|
committer | Andrew Newdigate <andrew@gitlab.com> | 2017-03-10 13:56:08 +0300 |
commit | e149e1f79aa7309e01c60f00544ef574741f682b (patch) | |
tree | 09a9bdc2a6fc54b7dd0331cac0c6c3f594b49c41 | |
parent | ebbce70eaf32627453635fb8ce2386a1477882e7 (diff) | |
parent | 5501fa5220f7721cd3d5152ee225b30cfb4ea591 (diff) |
Merge branch 'style' into 'master'
Add style guide
See merge request !93
-rw-r--r-- | STYLE.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/STYLE.md b/STYLE.md new file mode 100644 index 000000000..f2e77c11e --- /dev/null +++ b/STYLE.md @@ -0,0 +1,31 @@ +# Gitaly code style + +## Errors + +### Use %v when wrapping errors + +Use `%v` when wrapping errors with context. + + return fmt.Errorf("foo context: %v", err) + +### Use %q when interpolating strings + +Unless it would lead to incorrect results, always use `%q` when +interpolating strings. The `%q` operator quotes strings and escapes +spaces and non-printable characters. This can save a lot of debugging +time. + +## Tests + +### Table-driven tests + +We like table-driven tests ([Cheney blog post], [Golang wiki]). + +- It should be clear from error messages which test case in the table + is failing. Consider giving test cases a `name` attribute and + including that name in every error message inside the loop. +- Use `t.Errorf` inside a table test loop, not `t.Fatalf`: this + provides more feedback when fixing failing tests. + + [Cheney blog post]: https://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go + [Golang wiki]: https://github.com/golang/go/wiki/TableDrivenTests |