Skip to content

Commit 817ba51

Browse files
authored
Fix connect_timeout for gocloud (#56)
1 parent c43928d commit 817ba51

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

postgresql/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,13 @@ func (c *Config) featureSupported(name featureName) bool {
172172
}
173173

174174
func (c *Config) connParams() []string {
175-
params := map[string]string{
176-
"connect_timeout": strconv.Itoa(c.ConnectTimeoutSec),
177-
}
175+
params := map[string]string{}
178176

179-
// sslmode is not allowed with gocloud
177+
// sslmode and connect_timeout are not allowed with gocloud
180178
// (TLS is provided by gocloud directly)
181179
if c.Scheme == "postgres" {
182180
params["sslmode"] = c.SSLMode
181+
params["connect_timeout"] = strconv.Itoa(c.ConnectTimeoutSec)
183182
}
184183

185184
if c.featureSupported(featureFallbackApplicationName) {

postgresql/config_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ func TestConfigConnParams(t *testing.T) {
1414
input *Config
1515
want []string
1616
}{
17-
{&Config{ConnectTimeoutSec: 10}, []string{"connect_timeout=10"}},
17+
{&Config{Scheme: "postgres", SSLMode: "require", ConnectTimeoutSec: 10}, []string{"connect_timeout=10", "sslmode=require"}},
1818
{&Config{Scheme: "postgres", SSLMode: "disable"}, []string{"connect_timeout=0", "sslmode=disable"}},
19-
{&Config{Scheme: "awspostgres", SSLMode: "disable"}, []string{"connect_timeout=0"}},
20-
{&Config{ExpectedVersion: semver.MustParse("9.0.0"), ApplicationName: "Terraform provider"}, []string{"connect_timeout=0", "fallback_application_name=Terraform+provider"}},
21-
{&Config{ExpectedVersion: semver.MustParse("8.0.0"), ApplicationName: "Terraform provider"}, []string{"connect_timeout=0"}},
22-
{&Config{SSLClientCert: &ClientCertificateConfig{CertificatePath: "/path/to/public-certificate.pem", KeyPath: "/path/to/private-key.pem"}}, []string{"connect_timeout=0", "sslcert=%2Fpath%2Fto%2Fpublic-certificate.pem", "sslkey=%2Fpath%2Fto%2Fprivate-key.pem"}},
23-
{&Config{SSLRootCertPath: "/path/to/root.pem"}, []string{"connect_timeout=0", "sslrootcert=%2Fpath%2Fto%2Froot.pem"}},
19+
{&Config{Scheme: "awspostgres", ConnectTimeoutSec: 10}, []string{}},
20+
{&Config{Scheme: "awspostgres", SSLMode: "disable"}, []string{}},
21+
{&Config{ExpectedVersion: semver.MustParse("9.0.0"), ApplicationName: "Terraform provider"}, []string{"fallback_application_name=Terraform+provider"}},
22+
{&Config{ExpectedVersion: semver.MustParse("8.0.0"), ApplicationName: "Terraform provider"}, []string{}},
23+
{&Config{SSLClientCert: &ClientCertificateConfig{CertificatePath: "/path/to/public-certificate.pem", KeyPath: "/path/to/private-key.pem"}}, []string{"sslcert=%2Fpath%2Fto%2Fpublic-certificate.pem", "sslkey=%2Fpath%2Fto%2Fprivate-key.pem"}},
24+
{&Config{SSLRootCertPath: "/path/to/root.pem"}, []string{"sslrootcert=%2Fpath%2Fto%2Froot.pem"}},
2425
}
2526

2627
for _, test := range tests {

0 commit comments

Comments
 (0)