mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: replace testing.Testing with flag lookup (#26552)
In our codebase we have an existing convention of using
`flag.Lookup("test.v")` instead of `testing.Testing()`. This avoids
pulling in the entire `testing` package. Another consequence: some of
our custom linters trigger upon import of the `testing` package which
can lead to unexpected linter errors.
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -2611,7 +2611,7 @@ func (q *querier) DeleteWorkspaceSubAgentByID(ctx context.Context, id uuid.UUID)
|
||||
}
|
||||
|
||||
func (q *querier) DisableForeignKeysAndTriggers(ctx context.Context) error {
|
||||
if !testing.Testing() {
|
||||
if flag.Lookup("test.v") == nil {
|
||||
return xerrors.Errorf("DisableForeignKeysAndTriggers is only allowed in tests")
|
||||
}
|
||||
return q.db.DisableForeignKeysAndTriggers(ctx)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mcpclient
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// mcpHTTPClient returns an isolated *http.Client when running
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// is a *http.Transport it is cloned; otherwise a minimal
|
||||
// transport with ProxyFromEnvironment is created as a fallback.
|
||||
func mcpHTTPClient() *http.Client {
|
||||
if !testing.Testing() {
|
||||
if flag.Lookup("test.v") == nil {
|
||||
return nil
|
||||
}
|
||||
if dt, ok := http.DefaultTransport.(*http.Transport); ok {
|
||||
|
||||
Reference in New Issue
Block a user