|
| 1 | +package box_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log" |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/google/uuid" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | + "github.com/tarantool/go-tarantool/v2" |
| 13 | + "github.com/tarantool/go-tarantool/v2/box" |
| 14 | + "github.com/tarantool/go-tarantool/v2/test_helpers" |
| 15 | +) |
| 16 | + |
| 17 | +var server = "127.0.0.1:3013" |
| 18 | +var dialer = tarantool.NetDialer{ |
| 19 | + Address: server, |
| 20 | + User: "test", |
| 21 | + Password: "test", |
| 22 | +} |
| 23 | + |
| 24 | +func validateInfo(t testing.TB, info box.Info) { |
| 25 | + var err error |
| 26 | + |
| 27 | + // Check all fields run correctly. |
| 28 | + _, err = uuid.Parse(info.UUID) |
| 29 | + require.NoErrorf(t, err, "validate instance uuid is valid") |
| 30 | + |
| 31 | + require.NotEmpty(t, info.Version) |
| 32 | + // Check that pid parsed correctly. |
| 33 | + require.NotEqual(t, info.PID, 0) |
| 34 | +} |
| 35 | + |
| 36 | +func TestBox_Sugar_Info(t *testing.T) { |
| 37 | + ctx := context.TODO() |
| 38 | + |
| 39 | + conn, err := tarantool.Connect(ctx, dialer, tarantool.Opts{}) |
| 40 | + require.NoError(t, err) |
| 41 | + |
| 42 | + info, err := box.New(conn).Info() |
| 43 | + require.NoError(t, err) |
| 44 | + |
| 45 | + validateInfo(t, info) |
| 46 | +} |
| 47 | + |
| 48 | +func TestBox_Info(t *testing.T) { |
| 49 | + ctx := context.TODO() |
| 50 | + |
| 51 | + conn, err := tarantool.Connect(ctx, dialer, tarantool.Opts{}) |
| 52 | + require.NoError(t, err) |
| 53 | + |
| 54 | + fut := conn.Do(box.NewInfoRequest()) |
| 55 | + require.NotNil(t, fut) |
| 56 | + |
| 57 | + resp := &box.InfoResponse{} |
| 58 | + err = fut.GetTyped(resp) |
| 59 | + require.NoError(t, err) |
| 60 | + |
| 61 | + validateInfo(t, resp.Info) |
| 62 | +} |
| 63 | + |
| 64 | +func runTestMain(m *testing.M) int { |
| 65 | + instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{ |
| 66 | + Dialer: dialer, |
| 67 | + InitScript: "testdata/config.lua", |
| 68 | + Listen: server, |
| 69 | + WaitStart: 100 * time.Millisecond, |
| 70 | + ConnectRetry: 10, |
| 71 | + RetryTimeout: 500 * time.Millisecond, |
| 72 | + }) |
| 73 | + defer test_helpers.StopTarantoolWithCleanup(instance) |
| 74 | + |
| 75 | + if err != nil { |
| 76 | + log.Printf("Failed to prepare test Tarantool: %s", err) |
| 77 | + return 1 |
| 78 | + } |
| 79 | + |
| 80 | + return m.Run() |
| 81 | +} |
| 82 | + |
| 83 | +func TestMain(m *testing.M) { |
| 84 | + code := runTestMain(m) |
| 85 | + os.Exit(code) |
| 86 | +} |
0 commit comments