Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions .claude/docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ issues.

### Test Package Naming

- **Test packages**: Use `package_test` naming (e.g., `identityprovider_test`) for black-box testing
- **Black-box tests**: Default to a `package foo_test` test file (e.g.,
`identityprovider_test`). This is what the `testpackage` linter enforces.
- **White-box / internal tests**: When a test needs to touch unexported
symbols, put it in a file named `*_internal_test.go` with `package foo`.
The `testpackage` linter's `skip-regexp` already exempts that filename
suffix, so no `//nolint:testpackage` directive is needed.
- **Do not add `//nolint:testpackage`.** If a test needs internal access,
rename the file to `*_internal_test.go` instead. A directive plus a
justification comment is strictly worse than the established naming
convention, and the repo standardizes on the latter.

## RFC Protocol Testing

Expand All @@ -50,7 +59,7 @@ issues.

### Test File Structure

```
```text
coderd/
├── oauth2.go # Implementation
├── oauth2_test.go # Main tests
Expand All @@ -69,20 +78,20 @@ coderd/

### Running Tests

| Command | Purpose |
|---------|---------|
| `make test` | Run all Go tests |
| `make test RUN=TestFunctionName` | Run specific test |
| `go test -v ./path/to/package -run TestFunctionName` | Run test with verbose output |
| `make test-race` | Run tests with Go race detector |
| `make test-e2e` | Run end-to-end tests |
| Command | Purpose |
|------------------------------------------------------|---------------------------------|
| `make test` | Run all Go tests |
| `make test RUN=TestFunctionName` | Run specific test |
| `go test -v ./path/to/package -run TestFunctionName` | Run test with verbose output |
| `make test-race` | Run tests with Go race detector |
| `make test-e2e` | Run end-to-end tests |

### Frontend Testing

| Command | Purpose |
|---------|---------|
| `pnpm test` | Run frontend tests |
| `pnpm check` | Run code checks |
| Command | Purpose |
|--------------|--------------------|
| `pnpm test` | Run frontend tests |
| `pnpm check` | Run code checks |
Comment on lines +81 to +94

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs lint drift, boutta put up a PR to prevent this from happening again.


## Common Testing Issues

Expand Down Expand Up @@ -218,6 +227,7 @@ func BenchmarkFunction(b *testing.B) {
```

Run benchmarks with:

```bash
go test -bench=. -benchmem ./package/path
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:testpackage // Tests private env helpers directly.
package reconnectingpty

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package agent //nolint:testpackage // Exercises internal agent secrets handling.
package agent

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apidump //nolint:testpackage // tests unexported internals
package apidump

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apidump //nolint:testpackage // tests unexported internals
package apidump

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package apidump //nolint:testpackage // shares test helpers with apidump_test.go
package apidump

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatcompletions //nolint:testpackage // tests unexported internals
package chatcompletions

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatcompletions //nolint:testpackage // tests unexported internals
package chatcompletions

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatcompletions //nolint:testpackage // tests unexported internals
package chatcompletions

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatcompletions //nolint:testpackage // tests unexported internals
package chatcompletions

import (
"io"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package messages //nolint:testpackage // tests unexported internals
package messages

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package messages //nolint:testpackage // tests unexported internals
package messages

import (
"io"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package messages //nolint:testpackage // tests unexported internals
package messages

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package messages //nolint:testpackage // tests unexported internals
package messages

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package responses //nolint:testpackage // tests unexported internals
package responses

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package responses //nolint:testpackage // tests unexported internals
package responses

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package responses //nolint:testpackage // tests unexported internals
package responses

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package responses //nolint:testpackage // tests unexported internals
package responses

import (
"io"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integrationtest //nolint:testpackage // tests unexported internals
package integrationtest

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aibridge //nolint:testpackage // tests unexported newPassthroughRouter
package aibridge

import (
"crypto/tls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package provider //nolint:testpackage // tests unexported internals
package provider

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package provider //nolint:testpackage // tests unexported internals
package provider

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package provider //nolint:testpackage // tests unexported internals
package provider

import (
"bytes"
Expand Down
1 change: 0 additions & 1 deletion coderd/oauth2provider/authorize_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:testpackage // Internal test for unexported hashOAuth2State helper.
package oauth2provider

import (
Expand Down
2 changes: 1 addition & 1 deletion coderd/templates_meta_update_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coderd //nolint:testpackage // Tests the unexported resolveTemplateMetaUpdate helper.
package coderd

import (
"reflect"
Expand Down
2 changes: 1 addition & 1 deletion coderd/x/chatd/advisor_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Accesses unexported advisor helpers.
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatdebug //nolint:testpackage // Checks unexported normalized structs against fantasy source types.
package chatdebug

import (
"reflect"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatdebug //nolint:testpackage // Uses unexported normalization helpers.
package chatdebug

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatdebug //nolint:testpackage // Uses unexported recorder helpers.
package chatdebug

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatdebug //nolint:testpackage // Uses unexported recorder helpers.
package chatdebug

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatdebug //nolint:testpackage // Uses unexported recorder helpers.
package chatdebug

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatloop //nolint:testpackage // Uses internal symbols.
package chatloop

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatloop //nolint:testpackage // Uses internal symbols.
package chatloop

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chattool //nolint:testpackage // Uses internal symbols.
package chattool

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chattool //nolint:testpackage // Uses internal symbols.
package chattool

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Uses internal cache state.
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Uses internal symbols.
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Uses internal symbols.
package chatd

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Keeps internal helper tests in-package.
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Tests internal title override helpers.
package chatd

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chatd //nolint:testpackage // Keeps chatd unit tests in the package.
package chatd

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:testpackage
package codersdk

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:testpackage // This test exercises the internal query builder directly because agent requests need a live tailnet connection.
package workspacesdk

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runner //nolint:testpackage // Tests unexported failure classification helpers.
package runner

import (
"testing"
Expand Down
Loading