|
| 1 | +package coderconnect |
| 2 | + |
| 3 | +import ( |
| 4 | +"time" |
| 5 | + |
| 6 | +"github.com/google/uuid" |
| 7 | +"golang.org/x/xerrors" |
| 8 | + |
| 9 | +"github.com/coder/coder/v2/codersdk" |
| 10 | +"github.com/coder/coder/v2/scaletest/harness" |
| 11 | +"github.com/coder/coder/v2/scaletest/workspacebuild" |
| 12 | +) |
| 13 | + |
| 14 | +typeUserConfigstruct { |
| 15 | +// OrganizationID is the ID of the organization to add the user to. |
| 16 | +OrganizationID uuid.UUID`json:"organization_id"` |
| 17 | +// Username is the username of the new user. |
| 18 | +Usernamestring`json:"username"` |
| 19 | +// Email is the email of the new user. |
| 20 | +Emailstring`json:"email"` |
| 21 | +// SessionToken is the session token of an already existing user. If set, no |
| 22 | +// user will be created. |
| 23 | +SessionTokenstring`json:"session_token"` |
| 24 | +} |
| 25 | + |
| 26 | +func (cUserConfig)Validate()error { |
| 27 | +ifc.OrganizationID==uuid.Nil { |
| 28 | +returnxerrors.New("organization_id must not be a nil UUID") |
| 29 | +} |
| 30 | +ifc.SessionToken!="" { |
| 31 | +ifc.Username!="" { |
| 32 | +returnxerrors.New("username must be empty when session_token is set") |
| 33 | +} |
| 34 | +ifc.Email!="" { |
| 35 | +returnxerrors.New("email must be empty when session_token is set") |
| 36 | +} |
| 37 | +} |
| 38 | + |
| 39 | +returnnil |
| 40 | +} |
| 41 | + |
| 42 | +typeConfigstruct { |
| 43 | +// User is the configuration for the user to create or use. |
| 44 | +UserUserConfig`json:"user"` |
| 45 | + |
| 46 | +// Workspace is the configuration for the workspace to create. The workspace |
| 47 | +// will be built using the new user. |
| 48 | +// |
| 49 | +// OrganizationID is ignored and set to the new user's organization ID. |
| 50 | +Workspace workspacebuild.Config`json:"workspace"` |
| 51 | + |
| 52 | +// WorkspaceCount is the number of workspaces to create. |
| 53 | +WorkspaceCountint64`json:"power_user_workspaces"` |
| 54 | + |
| 55 | +// WorkspaceUpdatesTimeout is how long to wait for all expected workspace updates. |
| 56 | +WorkspaceUpdatesTimeout time.Duration`json:"workspace_updates_timeout"` |
| 57 | + |
| 58 | +// DialTimeout is how long to wait for the Coder Connect endpoint to be |
| 59 | +// reachable. |
| 60 | +DialTimeout time.Duration`json:"dial_timeout"` |
| 61 | + |
| 62 | +// NoCleanup determines whether users and workspaces should be left after the test. |
| 63 | +NoCleanupbool`json:"no_cleanup"` |
| 64 | + |
| 65 | +Metrics*Metrics`json:"-"` |
| 66 | + |
| 67 | +MetricLabelValues []string`json:"metric_label_values"` |
| 68 | + |
| 69 | +// DialBarrier is used to ensure all runners have dialed the Coder Connect |
| 70 | +// endpoint before creating their workspace(s). |
| 71 | +DialBarrier*harness.Barrier`json:"-"` |
| 72 | +} |
| 73 | + |
| 74 | +func (cConfig)Validate()error { |
| 75 | +iferr:=c.User.Validate();err!=nil { |
| 76 | +returnxerrors.Errorf("user config: %w",err) |
| 77 | +} |
| 78 | +c.Workspace.OrganizationID=c.User.OrganizationID |
| 79 | +// This value will be overwritten during the test. |
| 80 | +c.Workspace.UserID=codersdk.Me |
| 81 | +iferr:=c.Workspace.Validate();err!=nil { |
| 82 | +returnxerrors.Errorf("workspace config: %w",err) |
| 83 | +} |
| 84 | + |
| 85 | +ifc.DialBarrier==nil { |
| 86 | +returnxerrors.New("dial barrier must be set") |
| 87 | +} |
| 88 | + |
| 89 | +ifc.WorkspaceUpdatesTimeout<=0 { |
| 90 | +returnxerrors.New("workspace_updates_timeout must be greater than 0") |
| 91 | +} |
| 92 | + |
| 93 | +ifc.DialTimeout<=0 { |
| 94 | +returnxerrors.New("dial_timeout must be greater than 0") |
| 95 | +} |
| 96 | + |
| 97 | +ifc.Metrics==nil { |
| 98 | +returnxerrors.New("metrics must be set") |
| 99 | +} |
| 100 | + |
| 101 | +returnnil |
| 102 | +} |