diff --git a/.golangci.yml b/.golangci.yml index c75dcf23b8..423acdca01 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,6 +44,7 @@ linters: - musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false] - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] - nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] + - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false] - prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false] - predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] - promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] diff --git a/internal/namespaces/rdb/v1/custom_url_test.go b/internal/namespaces/rdb/v1/custom_url_test.go index 768f957592..d174f160df 100644 --- a/internal/namespaces/rdb/v1/custom_url_test.go +++ b/internal/namespaces/rdb/v1/custom_url_test.go @@ -2,6 +2,8 @@ package rdb_test import ( "fmt" + "net" + "strconv" "testing" "github.com/scaleway/scaleway-cli/v2/internal/core" @@ -21,7 +23,7 @@ func Test_UserGetURL(t *testing.T) { func(t *testing.T, ctx *core.CheckFuncCtx) { ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port - expected := fmt.Sprintf("postgresql://%s@%s:%d", user, ip, port) + expected := fmt.Sprintf("postgresql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) assert.Equal(t, expected, ctx.Result) }, ), @@ -39,7 +41,7 @@ func Test_UserGetURL(t *testing.T) { func(t *testing.T, ctx *core.CheckFuncCtx) { ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port - expected := fmt.Sprintf("mysql://%s@%s:%d", user, ip, port) + expected := fmt.Sprintf("mysql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) assert.Equal(t, expected, ctx.Result) }, ), @@ -62,7 +64,7 @@ func Test_UserGetURL(t *testing.T) { func(t *testing.T, ctx *core.CheckFuncCtx) { ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port - expected := fmt.Sprintf("postgresql://%s@%s:%d", customUserName, ip, port) + expected := fmt.Sprintf("postgresql://%s@%s", customUserName, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) assert.Equal(t, expected, ctx.Result) }, ), @@ -81,7 +83,7 @@ func Test_UserGetURL(t *testing.T) { func(t *testing.T, ctx *core.CheckFuncCtx) { ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port - expected := fmt.Sprintf("postgresql://%s@%s:%d/%s", user, ip, port, customDBName) + expected := fmt.Sprintf("postgresql://%s@%s/%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))), customDBName) assert.Equal(t, expected, ctx.Result) }, ), @@ -101,7 +103,7 @@ func Test_DatabaseGetURL(t *testing.T) { func(t *testing.T, ctx *core.CheckFuncCtx) { ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port - expected := fmt.Sprintf("postgresql://%s@%s:%d", user, ip, port) + expected := fmt.Sprintf("postgresql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) assert.Equal(t, expected, ctx.Result) }, ),