@@ -157,28 +157,68 @@ func TestServer(t *testing.T) {
157
157
t .Run ("PostgresURLFromFlags" , func (t * testing.T ) {
158
158
t .Parallel ()
159
159
160
+ if runtime .GOOS != "linux" || testing .Short () {
161
+ // Skip on non-Linux because it spawns a PostgreSQL instance.
162
+ t .SkipNow ()
163
+ }
164
+ connectionURL , err := dbtestutil .Open (t )
165
+ require .NoError (t , err )
166
+
167
+ pgURL , err := url .Parse (connectionURL )
168
+ require .NoError (t , err )
169
+ password , _ := pgURL .User .Password ()
170
+ database := strings .TrimPrefix (pgURL .Path , "/" )
171
+
172
+ ctx , cancelFunc := context .WithTimeout (context .Background (), testutil .WaitSuperLong * 3 )
173
+ defer cancelFunc ()
174
+
160
175
inv , cfg := clitest .New (t ,
176
+ "server" ,
177
+ "--http-address" , ":0" ,
178
+ "--access-url" , "https://foobarbaz.mydomain" ,
179
+ "--cache-dir" , t .TempDir (),
180
+ "--postgres-host" , pgURL .Hostname (),
181
+ "--postgres-port" , pgURL .Port (),
182
+ "--postgres-username" , pgURL .User .Username (),
183
+ "--postgres-password" , password ,
184
+ "--postgres-database" , database ,
185
+ "--postgres-options" , pgURL .Query ().Encode (),
186
+ )
187
+
188
+ clitest .Start (t , inv .WithContext (ctx ))
189
+ accessURL := waitAccessURL (t , cfg )
190
+ client := codersdk .New (accessURL )
191
+
192
+ _ , err = client .CreateFirstUser (ctx , coderdtest .FirstUserParams )
193
+ require .NoError (t , err )
194
+ })
195
+
196
+ t .Run ("InvalidPostgresConnectionFlags" , func (t * testing.T ) {
197
+ t .Parallel ()
198
+
199
+ ctx , cancelFunc := context .WithTimeout (context .Background (), testutil .WaitSuperLong * 3 )
200
+ defer cancelFunc ()
201
+
202
+ inv , _ := clitest .New (t ,
161
203
"server" ,
162
204
"--http-address" , ":0" ,
163
205
"--access-url" , "https://foobarbaz.mydomain" ,
164
206
"--cache-dir" , t .TempDir (),
165
207
"--postgres-host" , "localhost" ,
208
+ "--postgres-host" , "localhost" ,
166
209
"--postgres-port" , "5432" ,
167
210
"--postgres-username" , "coder" ,
168
211
"--postgres-password" , "password" ,
169
212
"--postgres-database" , "coder" ,
170
213
"--postgres-options" , "sslmode=disable" ,
214
+ "--postgres-url" , "postgres://coder:password@localhost:5432/coder?sslmode=disable" ,
171
215
)
172
216
173
- pty := ptytest .New (t ).Attach (inv )
174
-
175
- clitest .Start (t , inv )
176
-
177
- // Just wait for startup
178
- _ = waitAccessURL (t , cfg )
179
-
180
- pty .ExpectMatch ("Created PostgreSQL URL from provided flags" )
217
+ err := inv .WithContext (ctx ).Run ()
218
+ require .Error (t , err )
219
+ require .ErrorContains (t , err , "cannot specify both --postgres-url and individual postgres connection flags (--postgres-host, --postgres-username, etc). Please use only one connection method" )
181
220
})
221
+
182
222
t .Run ("BuiltinPostgres" , func (t * testing.T ) {
183
223
t .Parallel ()
184
224
if testing .Short () {
0 commit comments