@@ -180,24 +180,24 @@ func TestServer(t *testing.T) {
180
180
return err == nil && rawURL != ""
181
181
}, superDuperLong , testutil .IntervalFast , "failed to get access URL" )
182
182
})
183
-
183
+
184
184
t .Run ("PostgresConnectionParams" , func (t * testing.T ) {
185
185
if testing .Short () {
186
186
t .SkipNow ()
187
187
}
188
188
t .Parallel ()
189
-
189
+
190
190
// Use URL of built-in test database
191
191
dbURL , err := dbtestutil .Open (t )
192
192
require .NoError (t , err )
193
-
194
- // Rather than testing individual parameters directly (which would require access to
193
+
194
+ // Rather than testing individual parameters directly (which would require access to
195
195
// unexported struct fields), test the CLI flags with the actual server
196
-
196
+
197
197
// Parse the URL to extract components
198
198
u , err := url .Parse (dbURL )
199
199
require .NoError (t , err , "Failed to parse database URL" )
200
-
200
+
201
201
// Extract components
202
202
username := u .User .Username ()
203
203
password , _ := u .User .Password ()
@@ -207,11 +207,11 @@ func TestServer(t *testing.T) {
207
207
port = "5432" // Use default PostgreSQL port
208
208
}
209
209
database := strings .TrimPrefix (u .Path , "/" )
210
-
210
+
211
211
// Test with CLI flags
212
212
t .Run ("WithFlags" , func (t * testing.T ) {
213
213
t .Parallel ()
214
-
214
+
215
215
inv , cfg := clitest .New (t ,
216
216
"server" ,
217
217
"--http-address" , ":0" ,
@@ -223,40 +223,40 @@ func TestServer(t *testing.T) {
223
223
"--postgres-database" , database ,
224
224
"--postgres-options" , "sslmode=disable" ,
225
225
)
226
-
226
+
227
227
const longTimeout = testutil .WaitLong * 3
228
228
ctx := testutil .Context (t , longTimeout )
229
229
clitest .Start (t , inv .WithContext (ctx ))
230
-
230
+
231
231
//nolint:gocritic // Test server takes a while to start
232
232
require .Eventually (t , func () bool {
233
233
rawURL , err := cfg .URL ().Read ()
234
234
return err == nil && rawURL != ""
235
235
}, longTimeout , testutil .IntervalFast , "failed to get access URL with individual PostgreSQL parameters" )
236
236
})
237
-
237
+
238
238
// Test with environment variables
239
239
t .Run ("WithEnvironmentVariables" , func (t * testing.T ) {
240
240
t .Parallel ()
241
-
241
+
242
242
inv , cfg := clitest .New (t ,
243
243
"server" ,
244
244
"--http-address" , ":0" ,
245
245
"--access-url" , "http://example.com" ,
246
246
)
247
-
247
+
248
248
// Set environment variables
249
249
inv .Environ .Set ("CODER_PG_HOST" , host )
250
250
inv .Environ .Set ("CODER_PG_PORT" , port )
251
251
inv .Environ .Set ("CODER_PG_USERNAME" , username )
252
252
inv .Environ .Set ("CODER_PG_PASSWORD" , password )
253
253
inv .Environ .Set ("CODER_PG_DATABASE" , database )
254
254
inv .Environ .Set ("CODER_PG_OPTIONS" , "sslmode=disable" )
255
-
255
+
256
256
const longTimeout = testutil .WaitLong * 3
257
257
ctx := testutil .Context (t , longTimeout )
258
258
clitest .Start (t , inv .WithContext (ctx ))
259
-
259
+
260
260
//nolint:gocritic // Test server takes a while to start
261
261
require .Eventually (t , func () bool {
262
262
rawURL , err := cfg .URL ().Read ()
0 commit comments