Skip to content

[testify-expert] Improve Test Quality: pkg/cli/validators_test.go #64817

Description

@github-actions

Current State

  • Test file: pkg/cli/validators_test.go (424 LOC, 4 test functions, ~60 table cases, 0 testify usage)
  • Source pair: pkg/cli/validators.go (48 LOC, 2 exported funcs: ValidateWorkflowName, ValidateWorkflowIntent)

Strengths

  • Table-driven with descriptive case names; t.Parallel() at top level.
  • Good boundary coverage (19/20 chars, whitespace trimming, unicode, long input).

Prioritized Improvements

1. Missing / high-value tests

  • ValidateWorkflowIntent uses len(trimmed) (bytes), not runes. Add a case like "日本語日本語日" (7 runes, 21 bytes) to pin the intended behavior; either fix the source to utf.RuneCountInString or document the byte semantics in the test.
  • ValidateWorkflowName: add cases for trailing newline ("abc\n"; confirms $ doesn't match before a final newline), non-ASCII letters ("wörkflow"), and a name with .md suffix.
  • Duplicate case sets: *_EdgeCases tests overlap with the main tests (e.g. boundary/whitespace cases); merge or dedupe.

2. Testify assertion upgrades

Before / after
// before
if tt.expectError {
    if err == nil { t.Errorf(...); return }
    if !strings.Contains(err.Error(), tt.errorMsg) { t.Errorf(...) }
} else if err != nil { t.Errorf(...) }

// after
if tt.expectError {
    require.Error(t, err, "ValidateWorkflowName(%q) should fail", tt.input)
    assert.Contains(t, err.Error(), tt.errorMsg)
    return
}
require.NoError(t, err, "ValidateWorkflowName(%q) should succeed", tt.input)

Use assert.EqualError when the full message is fixed. The strings import is then only needed for strings.Repeat.

3. Table-driven refactors

  • Split each table into valid / invalid slices ([]string and []struct{input, wantErr string}) so expectError bool + empty errorMsg disappear.
  • The _EdgeCases variants omit errorMsg; make error message checking consistent across all failing cases.
  • Add t.Parallel() inside t.Run closures (copy of tt is safe on current Go).

4. Organization / readability

  • Hoist the two repeated error strings into constants/vars to avoid drift from source.
  • Collapse 4 test functions into 2 (TestValidateWorkflowName, TestValidateWorkflowIntent) with grouped sections.

Acceptance Checklist

  • Import github.com/stretchr/testify/assert and require
  • Replace manual t.Errorf error checks with require.Error/require.NoError/assert.Contains
  • Add rune-vs-byte and trailing-newline cases
  • Merge duplicated edge-case tables
  • make test-unit passes

Generated by 🧪 Daily Testify Uber Super Expert · copilot · auto · 13.3 AIC · ⌖ 8.27 AIC · ⊞ 7.3K · ◷

  • expires on Oct 3, 2026, 10:04 AM UTC-08:00

Activity

  1. github-actions commented on Oct 3, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-10-03T18:04:38.811Z.

    Closed by Workflow

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions