| 90 | } |
| 91 | |
| 92 | func NewWithAPI(t *testing.T, options *Options) ( |
| 93 | *codersdk.Client, io.Closer, *coderd.API, codersdk.CreateFirstUserResponse, |
| 94 | ) { |
| 95 | t.Helper() |
| 96 | |
| 97 | if options == nil { |
| 98 | options = &Options{} |
| 99 | } |
| 100 | if options.Options == nil { |
| 101 | options.Options = &coderdtest.Options{} |
| 102 | } |
| 103 | require.False(t, options.DontAddFirstUser && !options.DontAddLicense, "DontAddFirstUser requires DontAddLicense") |
| 104 | setHandler, cancelFunc, serverURL, oop := coderdtest.NewOptions(t, options.Options) |
| 105 | coderAPI, err := coderd.New(context.Background(), &coderd.Options{ |
| 106 | RBAC: true, |
| 107 | ConnectionLogging: options.ConnectionLogging, |
| 108 | AuditLogging: options.AuditLogging, |
| 109 | BrowserOnly: options.BrowserOnly, |
| 110 | SCIMAPIKey: options.SCIMAPIKey, |
| 111 | DERPServerRelayAddress: serverURL.String(), |
| 112 | DERPServerRegionID: int(oop.DeploymentValues.DERP.Server.RegionID.Value()), |
| 113 | ReplicaSyncUpdateInterval: options.ReplicaSyncUpdateInterval, |
| 114 | ReplicaErrorGracePeriod: options.ReplicaErrorGracePeriod, |
| 115 | Options: oop, |
| 116 | EntitlementsUpdateInterval: options.EntitlementsUpdateInterval, |
| 117 | LicenseKeys: Keys, |
| 118 | ProxyHealthInterval: options.ProxyHealthInterval, |
| 119 | DefaultQuietHoursSchedule: oop.DeploymentValues.UserQuietHoursSchedule.DefaultSchedule.Value(), |
| 120 | ProvisionerDaemonPSK: options.ProvisionerDaemonPSK, |
| 121 | ExternalTokenEncryption: options.ExternalTokenEncryption, |
| 122 | }) |
| 123 | require.NoError(t, err) |
| 124 | setHandler(coderAPI.AGPL.RootHandler) |
| 125 | var provisionerCloser io.Closer = nopcloser{} |
| 126 | if options.IncludeProvisionerDaemon { |
| 127 | provisionerCloser = coderdtest.NewProvisionerDaemon(t, coderAPI.AGPL) |
| 128 | } |
| 129 | |
| 130 | t.Cleanup(func() { |
| 131 | cancelFunc() |
| 132 | _ = provisionerCloser.Close() |
| 133 | _ = coderAPI.Close() |
| 134 | }) |
| 135 | client := codersdk.New(serverURL) |
| 136 | client.HTTPClient = &http.Client{ |
| 137 | Transport: &http.Transport{ |
| 138 | TLSClientConfig: &tls.Config{ |
| 139 | //nolint:gosec |
| 140 | InsecureSkipVerify: true, |
| 141 | }, |
| 142 | }, |
| 143 | } |
| 144 | var user codersdk.CreateFirstUserResponse |
| 145 | if !options.DontAddFirstUser { |
| 146 | user = coderdtest.CreateFirstUser(t, client) |
| 147 | if !options.DontAddLicense { |
| 148 | lo := LicenseOptions{} |
| 149 | if options.LicenseOptions != nil { |