Skip to content

Commit

Permalink
draft: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
askalt committed Nov 10, 2023
1 parent 08d24c9 commit 91146f5
Show file tree
Hide file tree
Showing 30 changed files with 1,940 additions and 2,047 deletions.
12 changes: 6 additions & 6 deletions box_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestErrorTypeMPEncodeDecode(t *testing.T) {
func TestErrorTypeEval(t *testing.T) {
test_helpers.SkipIfErrorMessagePackTypeUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space)
Expand Down
32 changes: 0 additions & 32 deletions connection_test.go

This file was deleted.

10 changes: 7 additions & 3 deletions crud/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ const (

var exampleOpts = tarantool.Opts{
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}

var exampleDialer = tarantool.TtDialer{
Address: exampleServer,
User: "test",
Password: "test",
}

func exampleConnect() *tarantool.Connection {
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
conn, err := tarantool.Connect(ctx, exampleServer, exampleOpts)
conn, err := tarantool.Connect(ctx, exampleDialer, exampleOpts)
if err != nil {
panic("Connection is not established: " + err.Error())
}
Expand Down
15 changes: 10 additions & 5 deletions crud/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ var spaceName = "test"
var invalidSpaceName = "invalid"
var indexNo = uint32(0)
var indexName = "primary_index"

var dialer = tarantool.TtDialer{
Address: server,
User: "test",
Password: "test",
}

var opts = tarantool.Opts{
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}

var startOpts test_helpers.StartOpts = test_helpers.StartOpts{
InitScript: "testdata/config.lua",
Listen: server,
User: opts.User,
Pass: opts.Pass,
User: dialer.User,
Pass: dialer.Password,
WaitStart: 100 * time.Millisecond,
ConnectRetry: 10,
RetryTimeout: 500 * time.Millisecond,
Expand Down Expand Up @@ -109,7 +114,7 @@ var object = crud.MapObject{
func connect(t testing.TB) *tarantool.Connection {
for i := 0; i < 10; i++ {
ctx, cancel := test_helpers.GetConnectContext()
conn, err := tarantool.Connect(ctx, server, opts)
conn, err := tarantool.Connect(ctx, dialer, opts)
cancel()
if err != nil {
t.Fatalf("Failed to connect: %s", err)
Expand Down
29 changes: 16 additions & 13 deletions datetime/datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ var isDatetimeSupported = false
var server = "127.0.0.1:3013"
var opts = Opts{
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
var dialer = TtDialer{
Address: server,
User: "test",
Password: "test",
}

var spaceTuple1 = "testDatetime_1"
Expand Down Expand Up @@ -364,7 +367,7 @@ func TestDatetimeInterval(t *testing.T) {
func TestDatetimeTarantoolInterval(t *testing.T) {
skipIfDatetimeUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

tupleInsertSelectDelete(t, conn, tm)
Expand All @@ -516,7 +519,7 @@ func TestInvalidOffset(t *testing.T) {
func TestCustomTimezone(t *testing.T) {
skipIfDatetimeUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

for _, testcase := range datetimeSample {
Expand Down Expand Up @@ -705,7 +708,7 @@ func TestDatetimeInsertSelectDelete(t *testing.T) {
func TestDatetimeBoundaryRange(t *testing.T) {
skipIfDatetimeUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

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

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

tm := time.Unix(500, 1000).In(time.FixedZone(NoTimezone, 0))
Expand Down Expand Up @@ -1168,8 +1171,8 @@ func runTestMain(m *testing.M) int {
instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{
InitScript: "config.lua",
Listen: server,
User: opts.User,
Pass: opts.Pass,
User: dialer.User,
Pass: dialer.Password,
WaitStart: 100 * time.Millisecond,
ConnectRetry: 10,
RetryTimeout: 500 * time.Millisecond,
Expand Down
8 changes: 4 additions & 4 deletions datetime/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
// Example demonstrates how to use tuples with datetime. To enable support of
// datetime import tarantool/datetime package.
func Example() {
opts := tarantool.Opts{
User: "test",
Pass: "test",
dialer := tarantool.TtDialer{
Address: "127.0.0.1:3013",
}
opts := tarantool.Opts{}
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
conn, err := tarantool.Connect(ctx, "127.0.0.1:3013", opts)
conn, err := tarantool.Connect(ctx, dialer, opts)
if err != nil {
fmt.Printf("Error in connect is %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion datetime/interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestIntervalSub(t *testing.T) {
func TestIntervalTarantoolEncoding(t *testing.T) {
skipIfDatetimeUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

cases := []Interval{
Expand Down
19 changes: 11 additions & 8 deletions decimal/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import (
var isDecimalSupported = false

var server = "127.0.0.1:3013"
var dialer = TtDialer{
Address: server,
User: "test",
Password: "test",
}
var opts = Opts{
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}

func skipIfDecimalUnsupported(t *testing.T) {
Expand Down Expand Up @@ -526,7 +529,7 @@ func BenchmarkDecodeStringFromBCD(b *testing.B) {
func TestSelect(t *testing.T) {
skipIfDecimalUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

number, err := decimal.NewFromString("-12.34")
Expand Down Expand Up @@ -572,7 +575,7 @@ func TestSelect(t *testing.T) {
func TestUnmarshal_from_decimal_new(t *testing.T) {
skipIfDecimalUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

samples := correctnessSamples
Expand Down Expand Up @@ -627,7 +630,7 @@ func assertInsert(t *testing.T, conn *Connection, numString string) {
func TestInsert(t *testing.T) {
skipIfDecimalUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

samples := correctnessSamples
Expand All @@ -642,7 +645,7 @@ func TestInsert(t *testing.T) {
func TestReplace(t *testing.T) {
skipIfDecimalUnsupported(t)

conn := test_helpers.ConnectWithValidation(t, server, opts)
conn := test_helpers.ConnectWithValidation(t, dialer, opts)
defer conn.Close()

number, err := decimal.NewFromString("-12.34")
Expand Down Expand Up @@ -697,8 +700,8 @@ func runTestMain(m *testing.M) int {
instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{
InitScript: "config.lua",
Listen: server,
User: opts.User,
Pass: opts.Pass,
User: dialer.User,
Pass: dialer.Password,
WaitStart: 100 * time.Millisecond,
ConnectRetry: 10,
RetryTimeout: 500 * time.Millisecond,
Expand Down
9 changes: 6 additions & 3 deletions decimal/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ import (
// import tarantool/decimal submodule.
func Example() {
server := "127.0.0.1:3013"
dialer := tarantool.TtDialer{
Address: server,
User: "test",
Password: "test",
}
opts := tarantool.Opts{
Timeout: 5 * time.Second,
User: "test",
Pass: "test",
}
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
client, err := tarantool.Connect(ctx, server, opts)
client, err := tarantool.Connect(ctx, dialer, opts)
cancel()
if err != nil {
log.Fatalf("Failed to connect: %s", err.Error())
Expand Down
Loading

0 comments on commit 91146f5

Please sign in to comment.