Skip to content

overrides_test.go assertions can fail without surfacing underlying file-I/O errors #22

Description

@jakewan

Context

Surfaced by Copilot review on PR #21 (the list-valued override-directive fix). Two new tests in that PR followed an existing project pattern; the review flagged the new instances. Deferred from #21 for cohesion — bundling the cleanup would have grown the PR past its primary concern.

Problem

Several tests in internal/overrides/overrides_test.go discard the error return from os.ReadFile(path) via the data, _ := os.ReadFile(path) pattern. When the read fails for any reason (filesystem state, permission issue, race in a parallel test environment), data is nil, string(data) is empty, and the subsequent strings.Contains or line-equality assertions all fail with diagnostics pointing at the assertion expectation. The actual root cause — that the test could not read the file at all — is invisible. A future engineer investigating the failure will look at the assertion logic and the override writer first, not at filesystem state.

Current instances:

  • TestWriteIncludesHeaderinternal/overrides/overrides_test.go:67
  • TestWriteSortsKeysinternal/overrides/overrides_test.go:88
  • TestWriteEmitsClearingLineForListValuedKeysinternal/overrides/overrides_test.go:136
  • TestWriteEmitsClearingLineForEachListValuedKeyinternal/overrides/overrides_test.go:172

Suggested approach

Replace each data, _ := os.ReadFile(path) with a checked read that calls t.Fatalf on error, matching the style already used for the corresponding Write errors elsewhere in the same tests. Scope the change to internal/overrides/overrides_test.go; the same pattern may exist in other test files but is out of scope here — file separately if found and discrepant.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions