Skip to content

Commit 62f0f85

Browse files
committed
improve test of sugar.DSN() + simplify call t.Fatal(fmt.Sprintf("")) to t.Fatalf("")
1 parent 9c0cfd0 commit 62f0f85

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

internal/dsn/dsn_test.go

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

33
import (
44
"context"
5-
"fmt"
65
"testing"
76

87
"github.com/ydb-platform/ydb-go-sdk/v3/config"
@@ -69,7 +68,7 @@ func TestParseConnectionString(t *testing.T) {
6968
t.Run(test.connectionString, func(t *testing.T) {
7069
options, err := Parse(test.connectionString)
7170
if !xerrors.Is(err, test.error) {
72-
t.Fatal(fmt.Sprintf("Received unexpected error:\n%+v", err))
71+
t.Fatalf("Received unexpected error:\n%+v", err)
7372
}
7473
config := config.New(options...)
7574
testutil.Equal(t, test.secure, config.Secure())
@@ -79,7 +78,7 @@ func TestParseConnectionString(t *testing.T) {
7978
if credentials := config.Credentials(); credentials != nil {
8079
token, err = credentials.Token(context.Background())
8180
if err != nil {
82-
t.Fatal(fmt.Sprintf("Received unexpected error:\n%+v", err))
81+
t.Fatalf("Received unexpected error:\n%+v", err)
8382
}
8483
} else {
8584
token = ""

sugar/dsn_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package sugar
22

33
import (
4-
"fmt"
54
"testing"
5+
6+
"github.com/ydb-platform/ydb-go-sdk/v3/config"
7+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/dsn"
68
)
79

810
func TestDSN(t *testing.T) {
@@ -39,9 +41,23 @@ func TestDSN(t *testing.T) {
3941
},
4042
} {
4143
t.Run(test.dsn, func(t *testing.T) {
42-
dsn := DSN(test.endpoint, test.database, test.secure)
43-
if dsn != test.dsn {
44-
t.Fatal(fmt.Sprintf("Unexpected result: %s, exp: %s", dsn, test.dsn))
44+
s := DSN(test.endpoint, test.database, test.secure)
45+
if s != test.dsn {
46+
t.Fatalf("Unexpected result: %s, exp: %s", s, test.dsn)
47+
}
48+
opts, err := dsn.Parse(s)
49+
if err != nil {
50+
t.Fatalf("")
51+
}
52+
config := config.New(opts...)
53+
if config.Endpoint() != test.endpoint {
54+
t.Fatalf("Unexpected endpoint: %s, exp: %s", config.Endpoint(), test.endpoint)
55+
}
56+
if config.Database() != test.database {
57+
t.Fatalf("Unexpected database: %s, exp: %s", config.Database(), test.database)
58+
}
59+
if config.Secure() != test.secure {
60+
t.Fatalf("Unexpected secure flag: %v, exp: %v", config.Secure(), test.secure)
4561
}
4662
})
4763
}

testutil/assert.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package testutil
22

33
import (
4-
"fmt"
54
"reflect"
65
"testing"
76
)
87

98
func Equal(t *testing.T, expected, actual interface{}) {
109
t.Helper()
1110
if !reflect.DeepEqual(expected, actual) {
12-
t.Fatal(fmt.Sprintf("Not equal: \n"+
13-
"expected: %#v\n"+
14-
"actual : %#v", expected, actual))
11+
t.Fatalf("Not equal:\n\tactual: %#v\n\texpected: %#v", actual, expected)
1512
}
1613
}
1714

1815
func NoError(t *testing.T, err error) {
1916
t.Helper()
2017
if err != nil {
21-
t.Fatal(fmt.Sprintf("Received unexpected error:\n%+v", err))
18+
t.Fatalf("Received unexpected error: %+v", err)
2219
}
2320
}
2421

0 commit comments

Comments
 (0)