Skip to content

Commit

Permalink
chore: add support for nosprintfhostport (#4067)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone authored Aug 22, 2024
1 parent 254fa49 commit 41aa419
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 7 additions & 5 deletions internal/namespaces/rdb/v1/custom_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package rdb_test

import (
"fmt"
"net"
"strconv"
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
Expand All @@ -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)
},
),
Expand All @@ -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)
},
),
Expand All @@ -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)
},
),
Expand All @@ -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)
},
),
Expand All @@ -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)
},
),
Expand Down

0 comments on commit 41aa419

Please sign in to comment.