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.
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package codersdk
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPagination_asRequestOption(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
uuid1 := uuid.New()
|
|
type fields struct {
|
|
AfterID uuid.UUID
|
|
Limit int
|
|
Offset int
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want url.Values
|
|
}{
|
|
{
|
|
name: "Test AfterID is set",
|
|
fields: fields{AfterID: uuid1},
|
|
want: url.Values{"after_id": []string{uuid1.String()}},
|
|
},
|
|
{
|
|
name: "Test Limit is set",
|
|
fields: fields{Limit: 10},
|
|
want: url.Values{"limit": []string{"10"}},
|
|
},
|
|
{
|
|
name: "Test Offset is set",
|
|
fields: fields{Offset: 10},
|
|
want: url.Values{"offset": []string{"10"}},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
p := Pagination{
|
|
AfterID: tt.fields.AfterID,
|
|
Limit: tt.fields.Limit,
|
|
Offset: tt.fields.Offset,
|
|
}
|
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
p.asRequestOption()(req)
|
|
got := req.URL.Query()
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|