44 "testing"
55 "time"
66
7+ "github.com/jackc/pgx/v5/pgconn"
78 "github.com/pashagolub/pgxmock/v4"
89 "github.com/stretchr/testify/assert"
910 "github.com/stretchr/testify/require"
@@ -16,7 +17,7 @@ import (
1617
1718const ImageName = "docker.io/postgres:17-alpine"
1819
19- func TestMonitoredDatabase_Connect (t * testing.T ) {
20+ func TestSourceConn_Connect (t * testing.T ) {
2021 pgContainer , err := postgres .Run (ctx ,
2122 ImageName ,
2223 testcontainers .WithWaitStrategy (
@@ -40,7 +41,7 @@ func TestMonitoredDatabase_Connect(t *testing.T) {
4041 err = md .Connect (ctx , sources.CmdOpts {})
4142 assert .NoError (t , err )
4243}
43- func TestMonitoredDatabase_GetDatabaseName (t * testing.T ) {
44+ func TestSourceConn_GetDatabaseName (t * testing.T ) {
4445 md := & sources.SourceConn {}
4546 md .ConnStr = "postgres://user:password@localhost:5432/mydatabase"
4647 expected := "mydatabase"
@@ -58,7 +59,7 @@ func TestMonitoredDatabase_GetDatabaseName(t *testing.T) {
5859 assert .Equal (t , expected , got , "GetDatabaseName() = %v, want %v" , got , expected )
5960}
6061
61- func TestMonitoredDatabase_SetDatabaseName (t * testing.T ) {
62+ func TestSourceConn_SetDatabaseName (t * testing.T ) {
6263 md := & sources.SourceConn {}
6364 md .ConnStr = "postgres://user:password@localhost:5432/mydatabase"
6465 expected := "mydatabase"
@@ -80,7 +81,7 @@ func TestMonitoredDatabase_SetDatabaseName(t *testing.T) {
8081 assert .Equal (t , expected , got , "GetDatabaseName() = %v, want %v" , got , expected )
8182}
8283
83- func TestMonitoredDatabase_IsPostgresSource (t * testing.T ) {
84+ func TestSourceConn_IsPostgresSource (t * testing.T ) {
8485 md := & sources.SourceConn {}
8586 md .Kind = sources .SourcePostgres
8687 assert .True (t , md .IsPostgresSource (), "IsPostgresSource() = false, want true" )
@@ -95,6 +96,21 @@ func TestMonitoredDatabase_IsPostgresSource(t *testing.T) {
9596 assert .True (t , md .IsPostgresSource (), "IsPostgresSource() = false, want true" )
9697}
9798
99+ func TestSourceConn_Ping (t * testing.T ) {
100+ db , err := pgxmock .NewPool ()
101+ require .NoError (t , err )
102+ md := & sources.SourceConn {Conn : db }
103+
104+ db .ExpectPing ()
105+ md .Kind = sources .SourcePostgres
106+ assert .NoError (t , md .Ping (ctx ), "Ping() = error, want nil" )
107+
108+ db .ExpectExec ("SHOW VERSION" ).WillReturnResult (pgconn .NewCommandTag ("SELECT 1" ))
109+ md .Conn = db
110+ md .Kind = sources .SourcePgBouncer
111+ assert .NoError (t , md .Ping (ctx ), "Ping() = error, want nil" )
112+ }
113+
98114type testSourceReader struct {
99115 sources.Sources
100116 error
0 commit comments