Skip to content

[testify-expert] Improve Test Quality: pkg/console/render_test.go #74185

Done

Description

@github-actions

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Current State

  • File: pkg/console/render_test.go (639 LOC, 22 test functions)
  • Source: pkg/console/render.go (807 LOC)
  • testify usage: 78 assert.*, only 1 require.*; 3 t.Run uses

Strengths

  • t.Parallel() used; table-driven tests for TestParseConsoleTag, TestIsZeroValue, TestFormatFieldValue.
  • Good boundary coverage in TestFormatNumber and embedded-struct cases.

Prioritized Improvements

1. Missing / high-value tests

  • FormatTokens (render.go:739) has no tests anywhere in pkg/console; add a table-driven test including 0, 999, 1000, 9999, 1_000_000 and negatives.
  • RenderStructWithOptions is only exercised indirectly (stream_contract_test.go, table_width_test.go); add direct cases for MaxWidth and Stderr options with slices of structs and maps.
  • FormatNumber negative inputs are untested.
  • RenderStruct with non-struct/nil/any(nil) input, unexported fields, and unsupported kinds (chan/func) has no tests.

2. Testify assertion upgrades

Details
  • Use require.* for preconditions whose failure makes later asserts meaningless (e.g. non-empty output before strings.Contains/line-splitting checks in TestRenderStruct_*, TestRenderSlice_*). Currently only line 585 does this.
  • Prefer assert.Contains/assert.NotContains over strings.Contains + assert.True where present.
  • Add assert.Empty/assert.NotEmpty for output checks where applicable.
// before
assert.True(t, strings.Contains(output, "Run ID"))
// after
require.NotEmpty(t, output)
assert.Contains(t, output, "Run ID")

3. Table-driven refactors

Details
  • TestFormatNumber loop has no t.Run; use named subtests so failures are isolated:
for _, tt := range tests {
    t.Run(strconv.Itoa(tt.input), func(t *testing.T) {
        t.Parallel()
        assert.Equal(t, tt.expected, FormatNumber(tt.input))
    })
}
  • Merge TestRenderStruct_EmbeddedStruct, _EmbeddedStructOmitEmptyAndPointer, _NestedEmbeddedStruct and TestRenderSlice_*EmbeddedStruct variants into tables of (input, wantContains, wantNotContains).
  • Add t.Parallel() inside subtests in TestIsZeroValue/TestFormatFieldValue.
  • Add zero-value cases for isZeroValue: map, nil interface, struct, float 0.0, empty array.

4. Organization / readability

Details
  • Group tests by function (RenderStruct, RenderSlice, formatting helpers) and move shared test types next to their usage.
  • Name TestFormatTag_* tests after the function under test for discoverability.

Acceptance Checklist

  • FormatTokens and RenderStructWithOptions tests added
  • require.* used for preconditions
  • TestFormatNumber converted to named subtests
  • Embedded-struct tests consolidated into tables
  • make test-unit passes

Generated by 🧪 Daily Testify Uber Super Expert · copilot · auto · ~15 AIC · ⊞ 9.1K · ◷

  • expires on Nov 4, 2026, 10:07 AM UTC-08:00

Activity

  1. github-actions commented on Nov 3, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Cloclo

    I've identified this issue as a good candidate for automated resolution and requested a Cloclo workflow run to fix it.

    If dispatch succeeds, Cloclo will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~2 AIC · ⊞ 13.3K · ◷

  2. github-actions commented on Nov 3, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Cloclo

    I have identified this issue as a good candidate for automated resolution and requested a Cloclo workflow run to fix it.

    If dispatch succeeds, Cloclo will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 13.5K · ◷

  3. github-actions commented on Nov 3, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 13.5K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions