@@ -34,10 +34,13 @@ import (
34
34
"go.uber.org/goleak"
35
35
"gopkg.in/yaml.v3"
36
36
37
+ "cdr.dev/slog/sloggers/slogtest"
38
+
37
39
"github.com/coder/coder/v2/cli"
38
40
"github.com/coder/coder/v2/cli/clitest"
39
41
"github.com/coder/coder/v2/cli/config"
40
42
"github.com/coder/coder/v2/coderd/coderdtest"
43
+ "github.com/coder/coder/v2/coderd/database/dbtestutil"
41
44
"github.com/coder/coder/v2/coderd/database/postgres"
42
45
"github.com/coder/coder/v2/coderd/telemetry"
43
46
"github.com/coder/coder/v2/codersdk"
@@ -1657,3 +1660,26 @@ func TestServerYAMLConfig(t *testing.T) {
1657
1660
1658
1661
require .Equal (t , string (wantByt ), string (got ))
1659
1662
}
1663
+
1664
+ func TestConnectToPostgres (t * testing.T ) {
1665
+ t .Parallel ()
1666
+
1667
+ if ! dbtestutil .WillUsePostgres () {
1668
+ t .Skip ("this test does not make sense without postgres" )
1669
+ }
1670
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
1671
+ t .Cleanup (cancel )
1672
+
1673
+ log := slogtest .Make (t , nil )
1674
+
1675
+ dbURL , closeFunc , err := postgres .Open ()
1676
+ require .NoError (t , err )
1677
+ t .Cleanup (closeFunc )
1678
+
1679
+ sqlDB , err := cli .ConnectToPostgres (ctx , log , "postgres" , dbURL )
1680
+ require .NoError (t , err )
1681
+ t .Cleanup (func () {
1682
+ _ = sqlDB .Close ()
1683
+ })
1684
+ require .NoError (t , sqlDB .PingContext (ctx ))
1685
+ }
0 commit comments