Skip to content

refactor(tests): update slice pattern table tests to map pattern (low risk tests)#320

Merged
mwbrooks merged 6 commits intomainfrom
mwbrooks-table-test-consistent-p3-slice-to-map-simple
Feb 2, 2026
Merged

refactor(tests): update slice pattern table tests to map pattern (low risk tests)#320
mwbrooks merged 6 commits intomainfrom
mwbrooks-table-test-consistent-p3-slice-to-map-simple

Conversation

@mwbrooks
Copy link
Member

Summary

Related #315 and #316

This pull request updates our existing Table Tests using the Slice Pattern to the Map Pattern.

While the Slice Pattern is the chosen format in Golang documentation and many Golang projects, we prefer the Map Pattern for the following reasons:

  • Map order is not guaranteed, so the tests are randomized each run. This prevents state from carrying over into the next tests, but can make debugging tests more difficult.
  • Test Case names are displayed on a single line improving readability

There is wrong answer (as far as we know), but we're going with maps for readability and reliability.

Reviewers

This only updates the simple use-cases in order to keep the PR an easy read. We have 47 remaining Table Tests using the Slice Pattern that will need to be handled later. Over half should be on the low-to-medium risk.

Requirements

@mwbrooks mwbrooks added this to the Next Release milestone Jan 31, 2026
@mwbrooks mwbrooks self-assigned this Jan 31, 2026
@mwbrooks mwbrooks requested a review from a team as a code owner January 31, 2026 05:59
@mwbrooks mwbrooks added code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment labels Jan 31, 2026
@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.61%. Comparing base (66766a9) to head (7a210a8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #320      +/-   ##
==========================================
+ Coverage   64.59%   64.61%   +0.02%     
==========================================
  Files         212      212              
  Lines       17755    17755              
==========================================
+ Hits        11469    11473       +4     
+ Misses       5210     5206       -4     
  Partials     1076     1076              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mwbrooks mwbrooks changed the title refactor(tests): update slice pattern table tests to map pattern (only low risk tests) refactor(tests): update slice pattern table tests to map pattern (low risk tests) Jan 31, 2026
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwbrooks Such nice changesets here! Thanks tons for splitting these reviews up into separate PRs 🌚 ✨

func Test_AppendStringIfNotMember(t *testing.T) {
tests := []struct {
name string
tests := map[string]struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ praise: Another thing I love about structured table tests is the guarantee of unique test names. While rare, it makes a failing test faster to find in past experience!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed and I believe we had a few duplicate names. While rare, it's just another "don't make me think" moment to have the compiler fail early.

Comment on lines -65 to -69
{name: "not_case_sensitive_success", listToCheck: []string{"hi", "hey"}, toFind: "Hey", isCaseSensitive: false, want: true},
{name: "case_sensitive_success", listToCheck: []string{"hi", "Hey"}, toFind: "Hey", isCaseSensitive: true, want: true},
{name: "case_sensitive_fail", listToCheck: []string{"hi", "hey", "hello", "apple", "pear"}, toFind: "Hey", isCaseSensitive: true, want: false},
{name: "not_case_sensitive_fail", listToCheck: []string{"hi", "hey", "hello", "apple", "pear"}, toFind: "Peach", isCaseSensitive: false, want: false},
{name: "not_case_sensitive_substring", listToCheck: []string{"hi", "hey hello"}, toFind: "hey", isCaseSensitive: false, want: false},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ praise: Thanks for separating fields onto new lines. It's much easier to review these changes!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem and glad you agree on the single line. I wonder if we can configure our linter to enforce this?

@mwbrooks
Copy link
Member Author

mwbrooks commented Feb 2, 2026

Thanks for the quick Monday morning review @zimeg! Hope you enjoyed it over a nice cup of coffee or tea ☕

@mwbrooks mwbrooks merged commit 2da1d1a into main Feb 2, 2026
8 checks passed
@mwbrooks mwbrooks deleted the mwbrooks-table-test-consistent-p3-slice-to-map-simple branch February 2, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants