mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
c650aabbef
My agent added `//nolint:testpackage` to a test file on one of my PRs. Again. This PR cleans it up across the entire repo and updates the in-repo conventions so future agents stop doing it. The repo already has a precedent for white-box tests that need to touch unexported symbols: `*_internal_test.go` (145+ existing files). The `testpackage` linter's default `skip-regexp` exempts that filename suffix, so the `//nolint:testpackage` directive is unnecessary in every case where someone reached for it. This PR renames 51 such files to `*_internal_test.go` via `git mv` so blame and history follow, and strips the dead directive from 2 files that were already correctly named (`coderd/oauth2provider/authorize_internal_test.go`, `coderd/x/chatd/advisor_internal_test.go`). `.claude/docs/TESTING.md` now documents the rule explicitly under *Test Package Naming*, which is imported into the root `AGENTS.md` via `@.claude/docs/TESTING.md`. The rule: prefer `package foo_test`; if you need internal access, rename the file to `*_internal_test.go` rather than adding a nolint directive.
99 lines
2.1 KiB
Go
99 lines
2.1 KiB
Go
package reconnectingpty
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestWithTerminalEnv(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
defaultLocale := "C.UTF-8"
|
|
if runtime.GOOS == "darwin" {
|
|
defaultLocale = "UTF-8"
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
env []string
|
|
wantLCCTYPE string
|
|
wantLCCTYPESet bool
|
|
}{
|
|
{
|
|
name: "adds locale when missing",
|
|
env: []string{"PATH=/bin"},
|
|
wantLCCTYPE: defaultLocale,
|
|
wantLCCTYPESet: true,
|
|
},
|
|
{
|
|
name: "adds locale when lang is not utf8",
|
|
env: []string{"LANG=C"},
|
|
wantLCCTYPE: defaultLocale,
|
|
wantLCCTYPESet: true,
|
|
},
|
|
{
|
|
name: "keeps utf8 lang",
|
|
env: []string{"LANG=C.UTF-8"},
|
|
},
|
|
{
|
|
name: "keeps unhyphenated utf8 lang",
|
|
env: []string{"LANG=C.UTF8"},
|
|
},
|
|
{
|
|
name: "keeps utf8 ctype",
|
|
env: []string{"LC_CTYPE=C.UTF-8"},
|
|
wantLCCTYPE: "C.UTF-8",
|
|
wantLCCTYPESet: true,
|
|
},
|
|
{
|
|
name: "overrides non utf8 ctype",
|
|
env: []string{"LANG=C.UTF-8", "LC_CTYPE=C"},
|
|
wantLCCTYPE: defaultLocale,
|
|
wantLCCTYPESet: true,
|
|
},
|
|
{
|
|
name: "keeps utf8 lc all",
|
|
env: []string{"LC_ALL=C.UTF-8"},
|
|
},
|
|
{
|
|
name: "preserves non empty lc all",
|
|
env: []string{"LC_ALL=C"},
|
|
},
|
|
{
|
|
name: "ignores empty lc all",
|
|
env: []string{"LC_ALL="},
|
|
wantLCCTYPE: defaultLocale,
|
|
wantLCCTYPESet: true,
|
|
},
|
|
{
|
|
name: "continues after empty lc all",
|
|
env: []string{"LC_ALL=", "LANG=C.UTF-8"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := withTerminalEnv(tt.env)
|
|
term, ok := envValue(got, "TERM")
|
|
require.True(t, ok)
|
|
require.Equal(t, xterm256Color, term)
|
|
|
|
wantLCCTYPE := tt.wantLCCTYPE
|
|
wantLCCTYPESet := tt.wantLCCTYPESet
|
|
if runtime.GOOS == "windows" {
|
|
wantLCCTYPE, wantLCCTYPESet = envValue(tt.env, "LC_CTYPE")
|
|
}
|
|
|
|
locale, ok := envValue(got, "LC_CTYPE")
|
|
require.Equal(t, wantLCCTYPESet, ok)
|
|
if wantLCCTYPESet {
|
|
require.Equal(t, wantLCCTYPE, locale)
|
|
}
|
|
})
|
|
}
|
|
}
|