diff --git a/adapter/cockroachdb/connection_pgx.go b/adapter/cockroachdb/connection_pgx.go index f196689c..695d6126 100644 --- a/adapter/cockroachdb/connection_pgx.go +++ b/adapter/cockroachdb/connection_pgx.go @@ -49,14 +49,14 @@ func (c ConnectionURL) String() (s string) { if host == "" { host = "127.0.0.1" } - if port == "" { - port = "26257" - } u = append(u, "host="+escaper.Replace(host)) - u = append(u, "port="+escaper.Replace(port)) } else { u = append(u, "host="+escaper.Replace(c.Host)) } + if port == "" { + port = "26257" + } + u = append(u, "port="+escaper.Replace(port)) } if c.Socket != "" { diff --git a/adapter/cockroachdb/connection_pgx_test.go b/adapter/cockroachdb/connection_pgx_test.go index 391d0fb4..2c27e1b8 100644 --- a/adapter/cockroachdb/connection_pgx_test.go +++ b/adapter/cockroachdb/connection_pgx_test.go @@ -42,15 +42,15 @@ func TestConnectionURL(t *testing.T) { // Adding a host. c.Host = "localhost" - assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String()) + assert.Equal(t, "host=localhost port=26257 sslmode=prefer statement_cache_capacity=0", c.String()) // Adding a username. c.User = "Anakin" - assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String()) + assert.Equal(t, `host=localhost port=26257 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String()) // Adding a password with special characters. c.Password = "Some Sort of ' Password" - assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String()) + assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=26257 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String()) // Adding a port. c.Host = "localhost:1234" diff --git a/adapter/cockroachdb/connection_pq.go b/adapter/cockroachdb/connection_pq.go index fb93390f..ce2c64fe 100644 --- a/adapter/cockroachdb/connection_pq.go +++ b/adapter/cockroachdb/connection_pq.go @@ -49,14 +49,14 @@ func (c ConnectionURL) String() (s string) { if host == "" { host = "127.0.0.1" } - if port == "" { - port = "26257" - } u = append(u, "host="+escaper.Replace(host)) - u = append(u, "port="+escaper.Replace(port)) } else { u = append(u, "host="+escaper.Replace(c.Host)) } + if port == "" { + port = "26257" + } + u = append(u, "port="+escaper.Replace(port)) } if c.Socket != "" { diff --git a/adapter/cockroachdb/connection_pq_test.go b/adapter/cockroachdb/connection_pq_test.go index 17c2a9a5..3fda0354 100644 --- a/adapter/cockroachdb/connection_pq_test.go +++ b/adapter/cockroachdb/connection_pq_test.go @@ -42,15 +42,15 @@ func TestConnectionURL(t *testing.T) { // Adding a host. c.Host = "localhost" - assert.Equal(t, "host=localhost sslmode=prefer", c.String()) + assert.Equal(t, "host=localhost port=26257 sslmode=prefer", c.String()) // Adding a username. c.User = "Anakin" - assert.Equal(t, `host=localhost sslmode=prefer user=Anakin`, c.String()) + assert.Equal(t, `host=localhost port=26257 sslmode=prefer user=Anakin`, c.String()) // Adding a password with special characters. c.Password = "Some Sort of ' Password" - assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String()) + assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=26257 sslmode=prefer user=Anakin`, c.String()) // Adding a port. c.Host = "localhost:1234"