@@ -78,6 +78,10 @@ import (
78
78
)
79
79
80
80
type Options struct {
81
+ // AccessURL denotes a custom access URL. By default we use the httptest
82
+ // server's URL. Setting this may result in unexpected behavior (especially
83
+ // with running agents).
84
+ AccessURL * url.URL
81
85
AppHostname string
82
86
AWSCertificates awsidentity.Certificates
83
87
Authorizer rbac.Authorizer
@@ -144,7 +148,7 @@ func newWithCloser(t *testing.T, options *Options) (*codersdk.Client, io.Closer)
144
148
return client , closer
145
149
}
146
150
147
- func NewOptions (t * testing.T , options * Options ) (func (http.Handler ), context.CancelFunc , * coderd.Options ) {
151
+ func NewOptions (t * testing.T , options * Options ) (func (http.Handler ), context.CancelFunc , * url. URL , * coderd.Options ) {
148
152
if options == nil {
149
153
options = & Options {}
150
154
}
@@ -214,6 +218,11 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
214
218
derpPort , err := strconv .Atoi (serverURL .Port ())
215
219
require .NoError (t , err )
216
220
221
+ accessURL := options .AccessURL
222
+ if accessURL == nil {
223
+ accessURL = serverURL
224
+ }
225
+
217
226
stunAddr , stunCleanup := stuntest .ServeWithPacketListener (t , nettype.Std {})
218
227
t .Cleanup (stunCleanup )
219
228
@@ -236,12 +245,12 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
236
245
mutex .Lock ()
237
246
defer mutex .Unlock ()
238
247
handler = h
239
- }, cancelFunc , & coderd.Options {
248
+ }, cancelFunc , serverURL , & coderd.Options {
240
249
AgentConnectionUpdateFrequency : 150 * time .Millisecond ,
241
250
// Force a long disconnection timeout to ensure
242
251
// agents are not marked as disconnected during slow tests.
243
252
AgentInactiveDisconnectTimeout : testutil .WaitShort ,
244
- AccessURL : serverURL ,
253
+ AccessURL : accessURL ,
245
254
AppHostname : options .AppHostname ,
246
255
AppHostnameRegex : appHostnameRegex ,
247
256
Logger : slogtest .Make (t , nil ).Leveled (slog .LevelDebug ),
@@ -298,15 +307,15 @@ func NewWithAPI(t *testing.T, options *Options) (*codersdk.Client, io.Closer, *c
298
307
if options == nil {
299
308
options = & Options {}
300
309
}
301
- setHandler , cancelFunc , newOptions := NewOptions (t , options )
310
+ setHandler , cancelFunc , serverURL , newOptions := NewOptions (t , options )
302
311
// We set the handler after server creation for the access URL.
303
312
coderAPI := coderd .New (newOptions )
304
313
setHandler (coderAPI .RootHandler )
305
314
var provisionerCloser io.Closer = nopcloser {}
306
315
if options .IncludeProvisionerDaemon {
307
316
provisionerCloser = NewProvisionerDaemon (t , coderAPI )
308
317
}
309
- client := codersdk .New (coderAPI . AccessURL )
318
+ client := codersdk .New (serverURL )
310
319
t .Cleanup (func () {
311
320
cancelFunc ()
312
321
_ = provisionerCloser .Close ()
0 commit comments