From 125ee9670eb3a779386a409bbbb6a870193b18d9 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 25 Jun 2022 13:43:16 -0500 Subject: [PATCH] Test TLS connection with pg_stat_ssl Because of the nbconn wrapper it is no longer possible to check if the conn is a *tls.Conn directly. This is actually a more reliable test anyway. --- pgconn/pgconn_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pgconn/pgconn_test.go b/pgconn/pgconn_test.go index 07b68995..357a99c1 100644 --- a/pgconn/pgconn_test.go +++ b/pgconn/pgconn_test.go @@ -4,7 +4,6 @@ import ( "bytes" "compress/gzip" "context" - "crypto/tls" "errors" "fmt" "io" @@ -66,9 +65,11 @@ func TestConnectTLS(t *testing.T) { conn, err := pgconn.Connect(context.Background(), connString) require.NoError(t, err) - if _, ok := conn.Conn().(*tls.Conn); !ok { - t.Error("not a TLS connection") - } + result := conn.ExecParams(context.Background(), `select ssl from pg_stat_ssl where pg_backend_pid() = pid;`, nil, nil, nil, nil).Read() + require.NoError(t, result.Err) + require.Len(t, result.Rows, 1) + require.Len(t, result.Rows[0], 1) + require.Equalf(t, "t", string(result.Rows[0][0]), "not a TLS connection") closeConn(t, conn) }