Skip to content

Commit 7df40b8

Browse files
authored
chore(coderd/coderdtest): use testing.TB for use in benchmarks (coder#10237)
1 parent 1e75762 commit 7df40b8

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

coderd/coderdtest/coderdtest.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func New(t testing.TB, options *Options) *codersdk.Client {
155155
// the provisioner. This is a temporary function while work is done to
156156
// standardize how provisioners are registered with coderd. The option
157157
// to include a provisioner is set to true for convenience.
158-
func NewWithProvisionerCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer) {
158+
func NewWithProvisionerCloser(t testing.TB, options *Options) (*codersdk.Client, io.Closer) {
159159
if options == nil {
160160
options = &Options{}
161161
}
@@ -532,7 +532,7 @@ func NewProvisionerDaemon(t testing.TB, coderAPI *coderd.API) io.Closer {
532532
return closer
533533
}
534534

535-
func NewExternalProvisionerDaemon(t *testing.T, client *codersdk.Client, org uuid.UUID, tags map[string]string) io.Closer {
535+
func NewExternalProvisionerDaemon(t testing.TB, client *codersdk.Client, org uuid.UUID, tags map[string]string) io.Closer {
536536
echoClient, echoServer := provisionersdk.MemTransportPipe()
537537
ctx, cancelFunc := context.WithCancel(context.Background())
538538
serveDone := make(chan struct{})
@@ -594,15 +594,15 @@ func CreateFirstUser(t testing.TB, client *codersdk.Client) codersdk.CreateFirst
594594
}
595595

596596
// CreateAnotherUser creates and authenticates a new user.
597-
func CreateAnotherUser(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, roles ...string) (*codersdk.Client, codersdk.User) {
597+
func CreateAnotherUser(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, roles ...string) (*codersdk.Client, codersdk.User) {
598598
return createAnotherUserRetry(t, client, organizationID, 5, roles)
599599
}
600600

601-
func CreateAnotherUserMutators(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, roles []string, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
601+
func CreateAnotherUserMutators(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, roles []string, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
602602
return createAnotherUserRetry(t, client, organizationID, 5, roles, mutators...)
603603
}
604604

605-
func createAnotherUserRetry(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, retries int, roles []string, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
605+
func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, retries int, roles []string, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
606606
req := codersdk.CreateUserRequest{
607607
Email: namesgenerator.GetRandomName(10) + "@coder.com",
608608
Username: randomUsername(t),
@@ -695,7 +695,7 @@ func createAnotherUserRetry(t *testing.T, client *codersdk.Client, organizationI
695695
// CreateTemplateVersion creates a template import provisioner job
696696
// with the responses provided. It uses the "echo" provisioner for compatibility
697697
// with testing.
698-
func CreateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, res *echo.Responses, mutators ...func(*codersdk.CreateTemplateVersionRequest)) codersdk.TemplateVersion {
698+
func CreateTemplateVersion(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, res *echo.Responses, mutators ...func(*codersdk.CreateTemplateVersionRequest)) codersdk.TemplateVersion {
699699
t.Helper()
700700
data, err := echo.Tar(res)
701701
require.NoError(t, err)
@@ -737,7 +737,7 @@ func CreateWorkspaceBuild(
737737

738738
// CreateTemplate creates a template with the "echo" provisioner for
739739
// compatibility with testing. The name assigned is randomly generated.
740-
func CreateTemplate(t *testing.T, client *codersdk.Client, organization uuid.UUID, version uuid.UUID, mutators ...func(*codersdk.CreateTemplateRequest)) codersdk.Template {
740+
func CreateTemplate(t testing.TB, client *codersdk.Client, organization uuid.UUID, version uuid.UUID, mutators ...func(*codersdk.CreateTemplateRequest)) codersdk.Template {
741741
req := codersdk.CreateTemplateRequest{
742742
Name: randomUsername(t),
743743
VersionID: version,
@@ -752,7 +752,7 @@ func CreateTemplate(t *testing.T, client *codersdk.Client, organization uuid.UUI
752752

753753
// UpdateTemplateVersion creates a new template version with the "echo" provisioner
754754
// and associates it with the given templateID.
755-
func UpdateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, res *echo.Responses, templateID uuid.UUID) codersdk.TemplateVersion {
755+
func UpdateTemplateVersion(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, res *echo.Responses, templateID uuid.UUID) codersdk.TemplateVersion {
756756
ctx := context.Background()
757757
data, err := echo.Tar(res)
758758
require.NoError(t, err)
@@ -768,15 +768,15 @@ func UpdateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID
768768
return templateVersion
769769
}
770770

771-
func UpdateActiveTemplateVersion(t *testing.T, client *codersdk.Client, templateID, versionID uuid.UUID) {
771+
func UpdateActiveTemplateVersion(t testing.TB, client *codersdk.Client, templateID, versionID uuid.UUID) {
772772
err := client.UpdateActiveTemplateVersion(context.Background(), templateID, codersdk.UpdateActiveTemplateVersion{
773773
ID: versionID,
774774
})
775775
require.NoError(t, err)
776776
}
777777

778778
// AwaitTemplateVersionJobRunning waits for the build to be picked up by a provisioner.
779-
func AwaitTemplateVersionJobRunning(t *testing.T, client *codersdk.Client, version uuid.UUID) codersdk.TemplateVersion {
779+
func AwaitTemplateVersionJobRunning(t testing.TB, client *codersdk.Client, version uuid.UUID) codersdk.TemplateVersion {
780780
t.Helper()
781781

782782
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
@@ -807,7 +807,7 @@ func AwaitTemplateVersionJobRunning(t *testing.T, client *codersdk.Client, versi
807807

808808
// AwaitTemplateVersionJobCompleted waits for the build to be completed. This may result
809809
// from cancelation, an error, or from completing successfully.
810-
func AwaitTemplateVersionJobCompleted(t *testing.T, client *codersdk.Client, version uuid.UUID) codersdk.TemplateVersion {
810+
func AwaitTemplateVersionJobCompleted(t testing.TB, client *codersdk.Client, version uuid.UUID) codersdk.TemplateVersion {
811811
t.Helper()
812812

813813
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
@@ -826,7 +826,7 @@ func AwaitTemplateVersionJobCompleted(t *testing.T, client *codersdk.Client, ver
826826
}
827827

828828
// AwaitWorkspaceBuildJobCompleted waits for a workspace provision job to reach completed status.
829-
func AwaitWorkspaceBuildJobCompleted(t *testing.T, client *codersdk.Client, build uuid.UUID) codersdk.WorkspaceBuild {
829+
func AwaitWorkspaceBuildJobCompleted(t testing.TB, client *codersdk.Client, build uuid.UUID) codersdk.WorkspaceBuild {
830830
t.Helper()
831831

832832
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
@@ -897,7 +897,7 @@ func AwaitWorkspaceAgents(t testing.TB, client *codersdk.Client, workspaceID uui
897897
// CreateWorkspace creates a workspace for the user and template provided.
898898
// A random name is generated for it.
899899
// To customize the defaults, pass a mutator func.
900-
func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UUID, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace {
900+
func CreateWorkspace(t testing.TB, client *codersdk.Client, organization uuid.UUID, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace {
901901
t.Helper()
902902
req := codersdk.CreateWorkspaceRequest{
903903
TemplateID: templateID,
@@ -915,7 +915,7 @@ func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UU
915915
}
916916

917917
// TransitionWorkspace is a convenience method for transitioning a workspace from one state to another.
918-
func MustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID, from, to database.WorkspaceTransition) codersdk.Workspace {
918+
func MustTransitionWorkspace(t testing.TB, client *codersdk.Client, workspaceID uuid.UUID, from, to database.WorkspaceTransition) codersdk.Workspace {
919919
t.Helper()
920920
ctx := context.Background()
921921
workspace, err := client.Workspace(ctx, workspaceID)
@@ -939,7 +939,7 @@ func MustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceID
939939
}
940940

941941
// MustWorkspace is a convenience method for fetching a workspace that should exist.
942-
func MustWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID) codersdk.Workspace {
942+
func MustWorkspace(t testing.TB, client *codersdk.Client, workspaceID uuid.UUID) codersdk.Workspace {
943943
t.Helper()
944944
ctx := context.Background()
945945
ws, err := client.Workspace(ctx, workspaceID)
@@ -952,7 +952,7 @@ func MustWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID)
952952

953953
// RequestExternalAuthCallback makes a request with the proper OAuth2 state cookie
954954
// to the external auth callback endpoint.
955-
func RequestExternalAuthCallback(t *testing.T, providerID string, client *codersdk.Client) *http.Response {
955+
func RequestExternalAuthCallback(t testing.TB, providerID string, client *codersdk.Client) *http.Response {
956956
client.HTTPClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
957957
return http.ErrUseLastResponse
958958
}
@@ -980,7 +980,7 @@ func RequestExternalAuthCallback(t *testing.T, providerID string, client *coders
980980
// NewGoogleInstanceIdentity returns a metadata client and ID token validator for faking
981981
// instance authentication for Google Cloud.
982982
// nolint:revive
983-
func NewGoogleInstanceIdentity(t *testing.T, instanceID string, expired bool) (*idtoken.Validator, *metadata.Client) {
983+
func NewGoogleInstanceIdentity(t testing.TB, instanceID string, expired bool) (*idtoken.Validator, *metadata.Client) {
984984
keyID, err := cryptorand.String(12)
985985
require.NoError(t, err)
986986
claims := jwt.MapClaims{
@@ -1042,7 +1042,7 @@ func NewGoogleInstanceIdentity(t *testing.T, instanceID string, expired bool) (*
10421042

10431043
// NewAWSInstanceIdentity returns a metadata client and ID token validator for faking
10441044
// instance authentication for AWS.
1045-
func NewAWSInstanceIdentity(t *testing.T, instanceID string) (awsidentity.Certificates, *http.Client) {
1045+
func NewAWSInstanceIdentity(t testing.TB, instanceID string) (awsidentity.Certificates, *http.Client) {
10461046
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
10471047
require.NoError(t, err)
10481048

@@ -1102,7 +1102,7 @@ func NewAWSInstanceIdentity(t *testing.T, instanceID string) (awsidentity.Certif
11021102

11031103
// NewAzureInstanceIdentity returns a metadata client and ID token validator for faking
11041104
// instance authentication for Azure.
1105-
func NewAzureInstanceIdentity(t *testing.T, instanceID string) (x509.VerifyOptions, *http.Client) {
1105+
func NewAzureInstanceIdentity(t testing.TB, instanceID string) (x509.VerifyOptions, *http.Client) {
11061106
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
11071107
require.NoError(t, err)
11081108

@@ -1182,7 +1182,7 @@ type nopcloser struct{}
11821182
func (nopcloser) Close() error { return nil }
11831183

11841184
// SDKError coerces err into an SDK error.
1185-
func SDKError(t *testing.T, err error) *codersdk.Error {
1185+
func SDKError(t testing.TB, err error) *codersdk.Error {
11861186
var cerr *codersdk.Error
11871187
require.True(t, errors.As(err, &cerr))
11881188
return cerr

0 commit comments

Comments
 (0)