Skip to content

Commit 92d217c

Browse files
committed
cockroachdb: set default port
1 parent cb6aebc commit 92d217c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Diff for: adapter/cockroachdb/connection_pgx.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ func (c ConnectionURL) String() (s string) {
4949
if host == "" {
5050
host = "127.0.0.1"
5151
}
52-
if port == "" {
53-
port = "26257"
54-
}
5552
u = append(u, "host="+escaper.Replace(host))
56-
u = append(u, "port="+escaper.Replace(port))
5753
} else {
5854
u = append(u, "host="+escaper.Replace(c.Host))
5955
}
56+
if port == "" {
57+
port = "26257"
58+
}
59+
u = append(u, "port="+escaper.Replace(port))
6060
}
6161

6262
if c.Socket != "" {

Diff for: adapter/cockroachdb/connection_pgx_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ func TestConnectionURL(t *testing.T) {
4242

4343
// Adding a host.
4444
c.Host = "localhost"
45-
assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String())
45+
assert.Equal(t, "host=localhost port=26257 sslmode=prefer statement_cache_capacity=0", c.String())
4646

4747
// Adding a username.
4848
c.User = "Anakin"
49-
assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
49+
assert.Equal(t, `host=localhost port=26257 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
5050

5151
// Adding a password with special characters.
5252
c.Password = "Some Sort of ' Password"
53-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
53+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=26257 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
5454

5555
// Adding a port.
5656
c.Host = "localhost:1234"

Diff for: adapter/cockroachdb/connection_pq.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ func (c ConnectionURL) String() (s string) {
4949
if host == "" {
5050
host = "127.0.0.1"
5151
}
52-
if port == "" {
53-
port = "26257"
54-
}
5552
u = append(u, "host="+escaper.Replace(host))
56-
u = append(u, "port="+escaper.Replace(port))
5753
} else {
5854
u = append(u, "host="+escaper.Replace(c.Host))
5955
}
56+
if port == "" {
57+
port = "26257"
58+
}
59+
u = append(u, "port="+escaper.Replace(port))
6060
}
6161

6262
if c.Socket != "" {

Diff for: adapter/cockroachdb/connection_pq_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ func TestConnectionURL(t *testing.T) {
4242

4343
// Adding a host.
4444
c.Host = "localhost"
45-
assert.Equal(t, "host=localhost sslmode=prefer", c.String())
45+
assert.Equal(t, "host=localhost port=26257 sslmode=prefer", c.String())
4646

4747
// Adding a username.
4848
c.User = "Anakin"
49-
assert.Equal(t, `host=localhost sslmode=prefer user=Anakin`, c.String())
49+
assert.Equal(t, `host=localhost port=26257 sslmode=prefer user=Anakin`, c.String())
5050

5151
// Adding a password with special characters.
5252
c.Password = "Some Sort of ' Password"
53-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String())
53+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=26257 sslmode=prefer user=Anakin`, c.String())
5454

5555
// Adding a port.
5656
c.Host = "localhost:1234"

0 commit comments

Comments
 (0)