Skip to content

Commit c846d06

Browse files
committed
draft: fix tests
1 parent 421a1e6 commit c846d06

30 files changed

+939
-1242
lines changed

box_error_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func TestErrorTypeMPEncodeDecode(t *testing.T) {
299299
func TestErrorTypeEval(t *testing.T) {
300300
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)
301301

302-
conn := test_helpers.ConnectWithValidation(t, server, opts)
302+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
303303
defer conn.Close()
304304

305305
for name, testcase := range tupleCases {
@@ -318,7 +318,7 @@ func TestErrorTypeEval(t *testing.T) {
318318
func TestErrorTypeEvalTyped(t *testing.T) {
319319
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)
320320

321-
conn := test_helpers.ConnectWithValidation(t, server, opts)
321+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
322322
defer conn.Close()
323323

324324
for name, testcase := range tupleCases {
@@ -336,7 +336,7 @@ func TestErrorTypeEvalTyped(t *testing.T) {
336336
func TestErrorTypeInsert(t *testing.T) {
337337
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)
338338

339-
conn := test_helpers.ConnectWithValidation(t, server, opts)
339+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
340340
defer conn.Close()
341341

342342
truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
@@ -374,7 +374,7 @@ func TestErrorTypeInsert(t *testing.T) {
374374
func TestErrorTypeInsertTyped(t *testing.T) {
375375
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)
376376

377-
conn := test_helpers.ConnectWithValidation(t, server, opts)
377+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
378378
defer conn.Close()
379379

380380
truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
@@ -416,7 +416,7 @@ func TestErrorTypeInsertTyped(t *testing.T) {
416416
func TestErrorTypeSelect(t *testing.T) {
417417
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)
418418

419-
conn := test_helpers.ConnectWithValidation(t, server, opts)
419+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
420420
defer conn.Close()
421421

422422
truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
@@ -461,7 +461,7 @@ func TestErrorTypeSelect(t *testing.T) {
461461
func TestErrorTypeSelectTyped(t *testing.T) {
462462
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)
463463

464-
conn := test_helpers.ConnectWithValidation(t, server, opts)
464+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
465465
defer conn.Close()
466466

467467
truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)

connection_test.go

-32
This file was deleted.

crud/example_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ const (
1717

1818
var exampleOpts = tarantool.Opts{
1919
Timeout: 5 * time.Second,
20-
User: "test",
21-
Pass: "test",
20+
}
21+
22+
var exampleDialer = tarantool.TtDialer{
23+
Address: exampleServer,
24+
User: "test",
25+
Password: "test",
2226
}
2327

2428
func exampleConnect() *tarantool.Connection {
2529
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
2630
defer cancel()
27-
conn, err := tarantool.Connect(ctx, exampleServer, exampleOpts)
31+
conn, err := tarantool.Connect(ctx, exampleDialer, exampleOpts)
2832
if err != nil {
2933
panic("Connection is not established: " + err.Error())
3034
}

crud/tarantool_test.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ var spaceName = "test"
2121
var invalidSpaceName = "invalid"
2222
var indexNo = uint32(0)
2323
var indexName = "primary_index"
24+
25+
var dialer = tarantool.TtDialer{
26+
Address: server,
27+
User: "test",
28+
Password: "test",
29+
}
30+
2431
var opts = tarantool.Opts{
2532
Timeout: 5 * time.Second,
26-
User: "test",
27-
Pass: "test",
2833
}
2934

3035
var startOpts test_helpers.StartOpts = test_helpers.StartOpts{
3136
InitScript: "testdata/config.lua",
3237
Listen: server,
33-
User: opts.User,
34-
Pass: opts.Pass,
3538
WaitStart: 100 * time.Millisecond,
3639
ConnectRetry: 10,
3740
RetryTimeout: 500 * time.Millisecond,
@@ -109,7 +112,7 @@ var object = crud.MapObject{
109112
func connect(t testing.TB) *tarantool.Connection {
110113
for i := 0; i < 10; i++ {
111114
ctx, cancel := test_helpers.GetConnectContext()
112-
conn, err := tarantool.Connect(ctx, server, opts)
115+
conn, err := tarantool.Connect(ctx, dialer, opts)
113116
cancel()
114117
if err != nil {
115118
t.Fatalf("Failed to connect: %s", err)
@@ -1339,7 +1342,7 @@ func TestUnitEmptySchema(t *testing.T) {
13391342
// is a separate function, see
13401343
// https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls
13411344
func runTestMain(m *testing.M) int {
1342-
inst, err := test_helpers.StartTarantool(startOpts)
1345+
inst, err := test_helpers.StartTarantool(startOpts, dialer)
13431346
defer test_helpers.StopTarantoolWithCleanup(inst)
13441347

13451348
if err != nil {

datetime/datetime_test.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ var isDatetimeSupported = false
4040
var server = "127.0.0.1:3013"
4141
var opts = Opts{
4242
Timeout: 5 * time.Second,
43-
User: "test",
44-
Pass: "test",
43+
}
44+
var dialer = TtDialer{
45+
Address: server,
46+
User: "test",
47+
Password: "test",
4548
}
4649

4750
var spaceTuple1 = "testDatetime_1"
@@ -364,7 +367,7 @@ func TestDatetimeInterval(t *testing.T) {
364367
func TestDatetimeTarantoolInterval(t *testing.T) {
365368
skipIfDatetimeUnsupported(t)
366369

367-
conn := test_helpers.ConnectWithValidation(t, server, opts)
370+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
368371
defer conn.Close()
369372

370373
dates := []string{
@@ -504,7 +507,7 @@ func TestInvalidOffset(t *testing.T) {
504507
t.Fatalf("Unexpected success: %v", dt)
505508
}
506509
if testcase.ok && isDatetimeSupported {
507-
conn := test_helpers.ConnectWithValidation(t, server, opts)
510+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
508511
defer conn.Close()
509512

510513
tupleInsertSelectDelete(t, conn, tm)
@@ -516,7 +519,7 @@ func TestInvalidOffset(t *testing.T) {
516519
func TestCustomTimezone(t *testing.T) {
517520
skipIfDatetimeUnsupported(t)
518521

519-
conn := test_helpers.ConnectWithValidation(t, server, opts)
522+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
520523
defer conn.Close()
521524

522525
customZone := "Europe/Moscow"
@@ -676,7 +679,7 @@ var datetimeSample = []struct {
676679
func TestDatetimeInsertSelectDelete(t *testing.T) {
677680
skipIfDatetimeUnsupported(t)
678681

679-
conn := test_helpers.ConnectWithValidation(t, server, opts)
682+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
680683
defer conn.Close()
681684

682685
for _, testcase := range datetimeSample {
@@ -705,7 +708,7 @@ func TestDatetimeInsertSelectDelete(t *testing.T) {
705708
func TestDatetimeBoundaryRange(t *testing.T) {
706709
skipIfDatetimeUnsupported(t)
707710

708-
conn := test_helpers.ConnectWithValidation(t, server, opts)
711+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
709712
defer conn.Close()
710713

711714
for _, tm := range append(lesserBoundaryTimes, boundaryTimes...) {
@@ -731,7 +734,7 @@ func TestDatetimeOutOfRange(t *testing.T) {
731734
func TestDatetimeReplace(t *testing.T) {
732735
skipIfDatetimeUnsupported(t)
733736

734-
conn := test_helpers.ConnectWithValidation(t, server, opts)
737+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
735738
defer conn.Close()
736739

737740
tm, err := time.Parse(time.RFC3339, "2007-01-02T15:04:05Z")
@@ -896,7 +899,7 @@ func (c *Tuple2) DecodeMsgpack(d *msgpack.Decoder) error {
896899
func TestCustomEncodeDecodeTuple1(t *testing.T) {
897900
skipIfDatetimeUnsupported(t)
898901

899-
conn := test_helpers.ConnectWithValidation(t, server, opts)
902+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
900903
defer conn.Close()
901904

902905
tm1, _ := time.Parse(time.RFC3339, "2010-05-24T17:51:56.000000009Z")
@@ -966,7 +969,7 @@ func TestCustomEncodeDecodeTuple1(t *testing.T) {
966969
func TestCustomDecodeFunction(t *testing.T) {
967970
skipIfDatetimeUnsupported(t)
968971

969-
conn := test_helpers.ConnectWithValidation(t, server, opts)
972+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
970973
defer conn.Close()
971974

972975
// Call function 'call_datetime_testdata' returning a custom tuples.
@@ -1010,7 +1013,7 @@ func TestCustomDecodeFunction(t *testing.T) {
10101013
func TestCustomEncodeDecodeTuple5(t *testing.T) {
10111014
skipIfDatetimeUnsupported(t)
10121015

1013-
conn := test_helpers.ConnectWithValidation(t, server, opts)
1016+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
10141017
defer conn.Close()
10151018

10161019
tm := time.Unix(500, 1000).In(time.FixedZone(NoTimezone, 0))
@@ -1168,12 +1171,10 @@ func runTestMain(m *testing.M) int {
11681171
instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{
11691172
InitScript: "config.lua",
11701173
Listen: server,
1171-
User: opts.User,
1172-
Pass: opts.Pass,
11731174
WaitStart: 100 * time.Millisecond,
11741175
ConnectRetry: 10,
11751176
RetryTimeout: 500 * time.Millisecond,
1176-
})
1177+
}, dialer)
11771178
defer test_helpers.StopTarantoolWithCleanup(instance)
11781179

11791180
if err != nil {

datetime/example_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020
// Example demonstrates how to use tuples with datetime. To enable support of
2121
// datetime import tarantool/datetime package.
2222
func Example() {
23-
opts := tarantool.Opts{
24-
User: "test",
25-
Pass: "test",
23+
dialer := tarantool.TtDialer{
24+
Address: "127.0.0.1:3013",
2625
}
26+
opts := tarantool.Opts{}
2727
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
2828
defer cancel()
29-
conn, err := tarantool.Connect(ctx, "127.0.0.1:3013", opts)
29+
conn, err := tarantool.Connect(ctx, dialer, opts)
3030
if err != nil {
3131
fmt.Printf("Error in connect is %v", err)
3232
return

datetime/interval_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestIntervalSub(t *testing.T) {
105105
func TestIntervalTarantoolEncoding(t *testing.T) {
106106
skipIfDatetimeUnsupported(t)
107107

108-
conn := test_helpers.ConnectWithValidation(t, server, opts)
108+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
109109
defer conn.Close()
110110

111111
cases := []Interval{

decimal/decimal_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ import (
2020
var isDecimalSupported = false
2121

2222
var server = "127.0.0.1:3013"
23+
var dialer = TtDialer{
24+
Address: server,
25+
User: "test",
26+
Password: "test",
27+
}
2328
var opts = Opts{
2429
Timeout: 5 * time.Second,
25-
User: "test",
26-
Pass: "test",
2730
}
2831

2932
func skipIfDecimalUnsupported(t *testing.T) {
@@ -526,7 +529,7 @@ func BenchmarkDecodeStringFromBCD(b *testing.B) {
526529
func TestSelect(t *testing.T) {
527530
skipIfDecimalUnsupported(t)
528531

529-
conn := test_helpers.ConnectWithValidation(t, server, opts)
532+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
530533
defer conn.Close()
531534

532535
number, err := decimal.NewFromString("-12.34")
@@ -572,7 +575,7 @@ func TestSelect(t *testing.T) {
572575
func TestUnmarshal_from_decimal_new(t *testing.T) {
573576
skipIfDecimalUnsupported(t)
574577

575-
conn := test_helpers.ConnectWithValidation(t, server, opts)
578+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
576579
defer conn.Close()
577580

578581
samples := correctnessSamples
@@ -627,7 +630,7 @@ func assertInsert(t *testing.T, conn *Connection, numString string) {
627630
func TestInsert(t *testing.T) {
628631
skipIfDecimalUnsupported(t)
629632

630-
conn := test_helpers.ConnectWithValidation(t, server, opts)
633+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
631634
defer conn.Close()
632635

633636
samples := correctnessSamples
@@ -642,7 +645,7 @@ func TestInsert(t *testing.T) {
642645
func TestReplace(t *testing.T) {
643646
skipIfDecimalUnsupported(t)
644647

645-
conn := test_helpers.ConnectWithValidation(t, server, opts)
648+
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
646649
defer conn.Close()
647650

648651
number, err := decimal.NewFromString("-12.34")
@@ -697,12 +700,10 @@ func runTestMain(m *testing.M) int {
697700
instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{
698701
InitScript: "config.lua",
699702
Listen: server,
700-
User: opts.User,
701-
Pass: opts.Pass,
702703
WaitStart: 100 * time.Millisecond,
703704
ConnectRetry: 10,
704705
RetryTimeout: 500 * time.Millisecond,
705-
})
706+
}, dialer)
706707
defer test_helpers.StopTarantoolWithCleanup(instance)
707708

708709
if err != nil {

decimal/example_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ import (
2222
// import tarantool/decimal submodule.
2323
func Example() {
2424
server := "127.0.0.1:3013"
25+
dialer := tarantool.TtDialer{
26+
Address: server,
27+
User: "test",
28+
Password: "test",
29+
}
2530
opts := tarantool.Opts{
2631
Timeout: 5 * time.Second,
27-
User: "test",
28-
Pass: "test",
2932
}
3033
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
31-
client, err := tarantool.Connect(ctx, server, opts)
34+
client, err := tarantool.Connect(ctx, dialer, opts)
3235
cancel()
3336
if err != nil {
3437
log.Fatalf("Failed to connect: %s", err.Error())

0 commit comments

Comments
 (0)