| 39 | } |
| 40 | |
| 41 | func (c Config) Validate() error { |
| 42 | if err := c.User.Validate(); err != nil { |
| 43 | return xerrors.Errorf("user config: %w", err) |
| 44 | } |
| 45 | c.Workspace.OrganizationID = c.User.OrganizationID |
| 46 | // This value will be overwritten during the test. |
| 47 | c.Workspace.UserID = codersdk.Me |
| 48 | if err := c.Workspace.Validate(); err != nil { |
| 49 | return xerrors.Errorf("workspace config: %w", err) |
| 50 | } |
| 51 | |
| 52 | if c.Workspace.Request.Name != "" { |
| 53 | return xerrors.New("workspace name cannot be overridden") |
| 54 | } |
| 55 | |
| 56 | if c.WorkspaceCount <= 0 { |
| 57 | return xerrors.New("workspace_count must be greater than 0") |
| 58 | } |
| 59 | |
| 60 | if c.DialBarrier == nil { |
| 61 | return xerrors.New("dial barrier must be set") |
| 62 | } |
| 63 | |
| 64 | if c.WorkspaceUpdatesTimeout <= 0 { |
| 65 | return xerrors.New("workspace_updates_timeout must be greater than 0") |
| 66 | } |
| 67 | |
| 68 | if c.DialTimeout <= 0 { |
| 69 | return xerrors.New("dial_timeout must be greater than 0") |
| 70 | } |
| 71 | |
| 72 | if c.Metrics == nil { |
| 73 | return xerrors.New("metrics must be set") |
| 74 | } |
| 75 | |
| 76 | return nil |
| 77 | } |