From 48c1a06ee869d4ad11528732ba7aeba641784dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Tue, 21 Feb 2023 16:07:14 -0800 Subject: [PATCH 1/2] Add recommendation on using table tests for single case tests. The exact wording is TBD - this is to start a discussion. My personal preference is to use table-test all the time, and would obviously would like it to be recommended. However, the primary goal is to avoid arguing in the code reviews. I am okay with the other version too (no table tests for single case tests), as long as we call something out here. --- style.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/style.md b/style.md index 83056249..b98777d5 100644 --- a/style.md +++ b/style.md @@ -3336,7 +3336,8 @@ k := User{ -Exception: Field names *may* be omitted in test tables when there are 3 or +Exception: Field names *may* be omitted in +when there are 3 or fewer fields. ```go @@ -3691,6 +3692,10 @@ for _, tt := range tests { } ``` +Prefer table-test (structured) style when possible even for a single test case - +this style makes the tests easier to extend in the future as the the “arguments under +test” are clearly specified via `have` and `want`. + Parallel tests, like some specialized loops (for example, those that spawn goroutines or capture references as part of the loop body), must take care to explicitly assign loop variables within the loop's scope to From 6b49f0955358b40aaed612d201c8345f5c855eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Tue, 21 Feb 2023 16:08:51 -0800 Subject: [PATCH 2/2] ops --- style.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/style.md b/style.md index b98777d5..916c70e8 100644 --- a/style.md +++ b/style.md @@ -3336,8 +3336,7 @@ k := User{ -Exception: Field names *may* be omitted in -when there are 3 or +Exception: Field names *may* be omitted in test tables when there are 3 or fewer fields. ```go