Skip to content

Commit 41aa419

Browse files
authored
chore: add support for nosprintfhostport (#4067)
1 parent 254fa49 commit 41aa419

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ linters:
4444
- musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false]
4545
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
4646
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
47+
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
4748
- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
4849
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
4950
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]

internal/namespaces/rdb/v1/custom_url_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package rdb_test
22

33
import (
44
"fmt"
5+
"net"
6+
"strconv"
57
"testing"
68

79
"github.com/scaleway/scaleway-cli/v2/internal/core"
@@ -21,7 +23,7 @@ func Test_UserGetURL(t *testing.T) {
2123
func(t *testing.T, ctx *core.CheckFuncCtx) {
2224
ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP
2325
port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port
24-
expected := fmt.Sprintf("postgresql://%s@%s:%d", user, ip, port)
26+
expected := fmt.Sprintf("postgresql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))))
2527
assert.Equal(t, expected, ctx.Result)
2628
},
2729
),
@@ -39,7 +41,7 @@ func Test_UserGetURL(t *testing.T) {
3941
func(t *testing.T, ctx *core.CheckFuncCtx) {
4042
ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP
4143
port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port
42-
expected := fmt.Sprintf("mysql://%s@%s:%d", user, ip, port)
44+
expected := fmt.Sprintf("mysql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))))
4345
assert.Equal(t, expected, ctx.Result)
4446
},
4547
),
@@ -62,7 +64,7 @@ func Test_UserGetURL(t *testing.T) {
6264
func(t *testing.T, ctx *core.CheckFuncCtx) {
6365
ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP
6466
port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port
65-
expected := fmt.Sprintf("postgresql://%s@%s:%d", customUserName, ip, port)
67+
expected := fmt.Sprintf("postgresql://%s@%s", customUserName, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))))
6668
assert.Equal(t, expected, ctx.Result)
6769
},
6870
),
@@ -81,7 +83,7 @@ func Test_UserGetURL(t *testing.T) {
8183
func(t *testing.T, ctx *core.CheckFuncCtx) {
8284
ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP
8385
port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port
84-
expected := fmt.Sprintf("postgresql://%s@%s:%d/%s", user, ip, port, customDBName)
86+
expected := fmt.Sprintf("postgresql://%s@%s/%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))), customDBName)
8587
assert.Equal(t, expected, ctx.Result)
8688
},
8789
),
@@ -101,7 +103,7 @@ func Test_DatabaseGetURL(t *testing.T) {
101103
func(t *testing.T, ctx *core.CheckFuncCtx) {
102104
ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP
103105
port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port
104-
expected := fmt.Sprintf("postgresql://%s@%s:%d", user, ip, port)
106+
expected := fmt.Sprintf("postgresql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))))
105107
assert.Equal(t, expected, ctx.Result)
106108
},
107109
),

0 commit comments

Comments
 (0)