coderdtest
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Variables
- func AwaitTemplateVersionJob(t *testing.T, client *codersdk.Client, version uuid.UUID) codersdk.TemplateVersion
- func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID, ...) []codersdk.WorkspaceResource
- func AwaitWorkspaceBuildJob(t *testing.T, client *codersdk.Client, build uuid.UUID) codersdk.WorkspaceBuild
- func CreateAnotherUser(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, ...) (*codersdk.Client, codersdk.User)
- func CreateAnotherUserMutators(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, ...) (*codersdk.Client, codersdk.User)
- func CreateFirstUser(t testing.TB, client *codersdk.Client) codersdk.CreateFirstUserResponse
- func CreateTemplate(t *testing.T, client *codersdk.Client, organization uuid.UUID, ...) codersdk.Template
- func CreateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, ...) codersdk.TemplateVersion
- func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UUID, ...) codersdk.Workspace
- func CreateWorkspaceBuild(t *testing.T, client *codersdk.Client, workspace codersdk.Workspace, ...) codersdk.WorkspaceBuild
- func DeploymentValues(t testing.TB) *codersdk.DeploymentValues
- func MustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID, ...) codersdk.Workspace
- func MustWorkspace(t *testing.T, client *codersdk.Client, workspaceID uuid.UUID) codersdk.Workspace
- func New(t testing.TB, options *Options) *codersdk.Client
- func NewAWSInstanceIdentity(t *testing.T, instanceID string) (awsidentity.Certificates, *http.Client)
- func NewAzureInstanceIdentity(t *testing.T, instanceID string) (x509.VerifyOptions, *http.Client)
- func NewExternalProvisionerDaemon(t *testing.T, client *codersdk.Client, org uuid.UUID, tags map[string]string) io.Closer
- func NewGoogleInstanceIdentity(t *testing.T, instanceID string, expired bool) (*idtoken.Validator, *metadata.Client)
- func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.CancelFunc, *url.URL, *coderd.Options)
- func NewProvisionerDaemon(t testing.TB, coderAPI *coderd.API) io.Closer
- func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *coderd.API)
- func NewWithProvisionerCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer)
- func RandomRBACAction() rbac.Action
- func RandomRBACObject() rbac.Object
- func RandomRBACSubject() rbac.Subject
- func RequestGitAuthCallback(t *testing.T, providerID string, client *codersdk.Client) *http.Response
- func SDKError(t *testing.T, err error) *codersdk.Error
- func UpdateTemplateVersion(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, ...) codersdk.TemplateVersion
- func VerifySwaggerDefinitions(t *testing.T, router chi.Router, swaggerComments []SwaggerComment)
- type ActionObjectPair
- type AuthCall
- type FakeAuthorizer
- type OIDCConfig
- func (*OIDCConfig) AuthCodeURL(state string, _ ...oauth2.AuthCodeOption) string
- func (o *OIDCConfig) EncodeClaims(t *testing.T, claims jwt.MapClaims) string
- func (*OIDCConfig) Exchange(_ context.Context, code string, _ ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (o *OIDCConfig) OIDCConfig(t *testing.T, userInfoClaims jwt.MapClaims, ...) *coderd.OIDCConfig
- func (*OIDCConfig) TokenSource(context.Context, *oauth2.Token) oauth2.TokenSource
- type Options
- type PreparedRecorder
- type RBACAsserter
- type RecordingAuthorizer
- func (r *RecordingAuthorizer) AllAsserted() error
- func (r *RecordingAuthorizer) AllCalls(actor *rbac.Subject) []AuthCall
- func (r *RecordingAuthorizer) AssertActor(t *testing.T, actor rbac.Subject, did ...ActionObjectPair)
- func (r *RecordingAuthorizer) AssertOutOfOrder(t *testing.T, actor rbac.Subject, did ...ActionObjectPair)
- func (r *RecordingAuthorizer) Authorize(ctx context.Context, subject rbac.Subject, action rbac.Action, ...) error
- func (*RecordingAuthorizer) Pair(action rbac.Action, object rbac.Objecter) ActionObjectPair
- func (r *RecordingAuthorizer) Prepare(ctx context.Context, subject rbac.Subject, action rbac.Action, ...) (rbac.PreparedAuthorized, error)
- func (r *RecordingAuthorizer) Reset()
- type SwaggerComment
Constants¶
This section is empty.
Variables¶
var AppSecurityKey = must(workspaceapps.KeyFromString("6465616e207761732068657265206465616e207761732068657265206465616e207761732068657265206465616e207761732068657265206465616e207761732068657265206465616e207761732068657265206465616e2077617320686572"))
AppSecurityKey is a 96-byte key used to sign JWTs and encrypt JWEs forworkspace app tokens in tests.
var FirstUserParams =codersdk.CreateFirstUserRequest{Email: "testuser@coder.com",Username: "testuser",Password: "SomeSecurePassword!",}
Functions¶
funcAwaitTemplateVersionJob¶added inv0.4.0
func AwaitTemplateVersionJob(t *testing.T, client *codersdk.Client, versionuuid.UUID)codersdk.TemplateVersion
AwaitTemplateImportJob awaits for an import job to reach completed status.
funcAwaitWorkspaceAgents¶
func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, workspaceIDuuid.UUID, agentNames ...string) []codersdk.WorkspaceResource
AwaitWorkspaceAgents waits for all resources with agents to be connected. Ifspecific agents are provided, it will wait for those agents to be connectedbut will not fail if other agents are not connected.
funcAwaitWorkspaceBuildJob¶
func AwaitWorkspaceBuildJob(t *testing.T, client *codersdk.Client, builduuid.UUID)codersdk.WorkspaceBuild
AwaitWorkspaceBuildJob waits for a workspace provision job to reach completed status.
funcCreateAnotherUser¶
func CreateAnotherUser(t *testing.T, client *codersdk.Client, organizationIDuuid.UUID, roles ...string) (*codersdk.Client,codersdk.User)
CreateAnotherUser creates and authenticates a new user.
funcCreateAnotherUserMutators¶added inv0.25.0
funcCreateFirstUser¶
CreateFirstUser creates a user with preset credentials and authenticateswith the passed in codersdk client.
funcCreateTemplate¶added inv0.4.0
func CreateTemplate(t *testing.T, client *codersdk.Client, organizationuuid.UUID, versionuuid.UUID, mutators ...func(*codersdk.CreateTemplateRequest))codersdk.Template
CreateTemplate creates a template with the "echo" provisioner forcompatibility with testing. The name assigned is randomly generated.
funcCreateTemplateVersion¶added inv0.4.0
func CreateTemplateVersion(t *testing.T, client *codersdk.Client, organizationIDuuid.UUID, res *echo.Responses, mutators ...func(*codersdk.CreateTemplateVersionRequest))codersdk.TemplateVersion
CreateTemplateVersion creates a template import provisioner jobwith the responses provided. It uses the "echo" provisioner for compatibilitywith testing.
funcCreateWorkspace¶
func CreateWorkspace(t *testing.T, client *codersdk.Client, organizationuuid.UUID, templateIDuuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest))codersdk.Workspace
CreateWorkspace creates a workspace for the user and template provided.A random name is generated for it.To customize the defaults, pass a mutator func.
funcCreateWorkspaceBuild¶added inv0.6.0
func CreateWorkspaceBuild(t *testing.T,client *codersdk.Client,workspacecodersdk.Workspace,transitiondatabase.WorkspaceTransition,mutators ...func(*codersdk.CreateWorkspaceBuildRequest),)codersdk.WorkspaceBuild
CreateWorkspaceBuild creates a workspace build for the given workspace and transition.
funcDeploymentValues¶added inv0.19.0
func DeploymentValues(ttesting.TB) *codersdk.DeploymentValues
funcMustTransitionWorkspace¶added inv0.6.3
func MustTransitionWorkspace(t *testing.T, client *codersdk.Client, workspaceIDuuid.UUID, from, todatabase.WorkspaceTransition)codersdk.Workspace
TransitionWorkspace is a convenience method for transitioning a workspace from one state to another.
funcMustWorkspace¶added inv0.6.3
MustWorkspace is a convenience method for fetching a workspace that should exist.
funcNewAWSInstanceIdentity¶
func NewAWSInstanceIdentity(t *testing.T, instanceIDstring) (awsidentity.Certificates, *http.Client)
NewAWSInstanceIdentity returns a metadata client and ID token validator for fakinginstance authentication for AWS.
funcNewAzureInstanceIdentity¶added inv0.4.4
NewAzureInstanceIdentity returns a metadata client and ID token validator for fakinginstance authentication for Azure.
funcNewExternalProvisionerDaemon¶added inv0.12.8
funcNewGoogleInstanceIdentity¶
func NewGoogleInstanceIdentity(t *testing.T, instanceIDstring, expiredbool) (*idtoken.Validator, *metadata.Client)
NewGoogleInstanceIdentity returns a metadata client and ID token validator for fakinginstance authentication for Google Cloud.nolint:revive
funcNewOptions¶added inv0.9.0
funcNewProvisionerDaemon¶
NewProvisionerDaemon launches a provisionerd instance configured to workwell with coderd testing. It registers the "echo" provisioner forquick testing.
funcNewWithAPI¶added inv0.6.1
NewWithAPI constructs an in-memory API instance and returns a client to talk to it.Most tests never need a reference to the API, but AuthorizationTest in this module uses it.Do not expose the API or wrath shall descend upon thee.
funcNewWithProvisionerCloser¶added inv0.7.6
NewWithProvisionerCloser returns a client as well as a handle to closethe provisioner. This is a temporary function while work is done tostandardize how provisioners are registered with coderd. The optionto include a provisioner is set to true for convenience.
funcRandomRBACAction¶added inv0.17.2
funcRandomRBACObject¶added inv0.17.2
funcRandomRBACSubject¶added inv0.17.2
funcRequestGitAuthCallback¶added inv0.18.0
RequestGitAuthCallback makes a request with the proper OAuth2 state cookieto the git auth callback endpoint.
funcUpdateTemplateVersion¶added inv0.5.6
func UpdateTemplateVersion(t *testing.T, client *codersdk.Client, organizationIDuuid.UUID, res *echo.Responses, templateIDuuid.UUID)codersdk.TemplateVersion
UpdateTemplateVersion creates a new template version with the "echo" provisionerand associates it with the given templateID.
funcVerifySwaggerDefinitions¶added inv0.15.0
func VerifySwaggerDefinitions(t *testing.T, router chi.Router, swaggerComments []SwaggerComment)
Types¶
typeActionObjectPair¶added inv0.17.0
typeFakeAuthorizer¶added inv0.17.0
type FakeAuthorizer struct {// AlwaysReturn is the error that will be returned by Authorize.AlwaysReturnerror}
FakeAuthorizer is an Authorizer that always returns the same error.
typeOIDCConfig¶added inv0.10.2
type OIDCConfig struct {// contains filtered or unexported fields}
funcNewOIDCConfig¶added inv0.10.2
func NewOIDCConfig(t *testing.T, issuerstring) *OIDCConfig
func (*OIDCConfig)AuthCodeURL¶added inv0.10.2
func (*OIDCConfig) AuthCodeURL(statestring, _ ...oauth2.AuthCodeOption)string
func (*OIDCConfig)EncodeClaims¶added inv0.10.2
func (*OIDCConfig)Exchange¶added inv0.10.2
func (*OIDCConfig) Exchange(_context.Context, codestring, _ ...oauth2.AuthCodeOption) (*oauth2.Token,error)
func (*OIDCConfig)OIDCConfig¶added inv0.10.2
func (o *OIDCConfig) OIDCConfig(t *testing.T, userInfoClaimsjwt.MapClaims, opts ...func(cfg *coderd.OIDCConfig)) *coderd.OIDCConfig
func (*OIDCConfig)TokenSource¶added inv0.10.2
func (*OIDCConfig) TokenSource(context.Context, *oauth2.Token)oauth2.TokenSource
typeOptions¶
type Options struct {// AccessURL denotes a custom access URL. By default we use the httptest// server's URL. Setting this may result in unexpected behavior (especially// with running agents).AccessURL *url.URLAppHostnamestringAWSCertificatesawsidentity.CertificatesAuthorizerrbac.AuthorizerAzureCertificatesx509.VerifyOptionsGithubOAuth2Config *coderd.GithubOAuth2ConfigRealIPConfig *httpmw.RealIPConfigOIDCConfig *coderd.OIDCConfigGoogleTokenValidator *idtoken.ValidatorSSHKeygenAlgorithmgitsshkey.AlgorithmAutobuildTicker <-chantime.TimeAutobuildStats chan<-autobuild.StatsAuditoraudit.AuditorTLSCertificates []tls.CertificateGitAuthConfigs []*gitauth.ConfigTrialGenerator func(context.Context,string)errorTemplateScheduleStoreschedule.TemplateScheduleStoreCoordinatortailnet.CoordinatorHealthcheckFunc func(ctxcontext.Context, apiKeystring) *healthcheck.ReportHealthcheckTimeouttime.DurationHealthcheckRefreshtime.Duration// All rate limits default to -1 (unlimited) in tests if not set.APIRateLimitintLoginRateLimitintFilesRateLimitint// IncludeProvisionerDaemon when true means to start an in-memory provisionerDIncludeProvisionerDaemonboolMetricsCacheRefreshIntervaltime.DurationAgentStatsRefreshIntervaltime.DurationDeploymentValues *codersdk.DeploymentValues// Set update check options to enable update check.UpdateCheckOptions *updatecheck.Options// Overriding the database is heavily discouraged.// It should only be used in cases where multiple Coder// test instances are running against the same database.Databasedatabase.StorePubsubpubsub.PubsubConfigSSHcodersdk.SSHConfigResponseSwaggerEndpointbool// Logger should only be overridden if you expect errors// as part of your test.Logger *slog.Logger}
typePreparedRecorder¶added inv0.17.0
type PreparedRecorder struct {// contains filtered or unexported fields}
PreparedRecorder is the prepared version of the RecordingAuthorizer.It records the Authorize() calls to the original recorder. If the calleruses CompileToSQL, all recording stops. This is to support parity betweenmemory and SQL backed dbs.
func (*PreparedRecorder)CompileToSQL¶added inv0.17.0
func (s *PreparedRecorder) CompileToSQL(ctxcontext.Context, cfgregosql.ConvertConfig) (string,error)
typeRBACAsserter¶added inv0.20.0
type RBACAsserter struct {Subjectrbac.SubjectRecorder *RecordingAuthorizer}
RBACAsserter is a helper for asserting that the correct RBAC checks areperformed. This struct is tied to a given user, and only authorizes callsfor this user are checked.
funcAssertRBAC¶added inv0.20.0
AssertRBAC returns an RBACAsserter for the given user. This asserter willallow asserting that the correct RBAC checks are performed for the given user.All checks that are not run against this user will be ignored.
func (RBACAsserter)AllCalls¶added inv0.20.0
func (aRBACAsserter) AllCalls() []AuthCall
AllCalls is for debugging. If you are not sure where calls are coming from,call this and use a debugger or print them. They have small callstackson them to help locate the 'Authorize' call.Only calls to Authorize by the given subject will be returned.Note that duplicate rbac calls are handled by the rbac.Cacher(), butwill be recorded twice. So AllCalls() returns calls regardless if theywere returned from the cached or not.
func (RBACAsserter)AssertChecked¶added inv0.20.0
func (aRBACAsserter) AssertChecked(t *testing.T, actionrbac.Action, objects ...interface{})
AssertChecked will assert a given rbac check was performed. It does not careabout order of checks, or any other checks. This is useful when you do notcare about asserting every check that was performed.
func (RBACAsserter)AssertInOrder¶added inv0.20.0
func (aRBACAsserter) AssertInOrder(t *testing.T, actionrbac.Action, objects ...interface{})
AssertInOrder must be called in the correct order of authz checks. If the objectsor actions are not in the correct order, the test will fail.
func (RBACAsserter)Reset¶added inv0.20.0
func (aRBACAsserter) Reset()RBACAsserter
Reset will clear all previously recorded authz calls.This is helpful when wanting to ignore checks run in test setup.
typeRecordingAuthorizer¶added inv0.9.0
type RecordingAuthorizer struct {sync.RWMutexCalled []AuthCallWrappedrbac.Authorizer}
RecordingAuthorizer wraps any rbac.Authorizer and records all Authorize()calls made. This is useful for testing as these calls can later be asserted.
func (*RecordingAuthorizer)AllAsserted¶added inv0.17.0
func (r *RecordingAuthorizer) AllAsserted()error
AllAsserted returns an error if all calls to Authorize() have not beenasserted and checked. This is useful for testing to ensure that allAuthorize() calls are checked in the unit test.
func (*RecordingAuthorizer)AllCalls¶added inv0.20.0
func (r *RecordingAuthorizer) AllCalls(actor *rbac.Subject) []AuthCall
AllCalls is useful for debugging.
func (*RecordingAuthorizer)AssertActor¶added inv0.17.0
func (r *RecordingAuthorizer) AssertActor(t *testing.T, actorrbac.Subject, did ...ActionObjectPair)
AssertActor asserts in order. If the order of authz calls does not match,this will fail.
func (*RecordingAuthorizer)AssertOutOfOrder¶added inv0.20.0
func (r *RecordingAuthorizer) AssertOutOfOrder(t *testing.T, actorrbac.Subject, did ...ActionObjectPair)
AssertOutOfOrder asserts that the given actor performed the given actionon the given objects. It does not care about the order of the calls.When marking authz calls as asserted, it will mark the first matchingcalls first.
func (*RecordingAuthorizer)Pair¶added inv0.17.0
func (*RecordingAuthorizer) Pair(actionrbac.Action, objectrbac.Objecter)ActionObjectPair
Pair is on the RecordingAuthorizer to be easy to find and keep the pkginterface smaller.
func (*RecordingAuthorizer)Reset¶added inv0.17.0
func (r *RecordingAuthorizer) Reset()
Reset clears the recorded Authorize() calls.
typeSwaggerComment¶added inv0.15.0
type SwaggerComment struct {// contains filtered or unexported fields}
funcParseSwaggerComments¶added inv0.15.0
func ParseSwaggerComments(dirs ...string) ([]SwaggerComment,error)