|
| 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:3014" |
| 18 | +var dialer = tarantool.NetDialer{ |
| 19 | + Address: server, |
| 20 | + User: "test", |
| 21 | + Password: "test", |
| 22 | +} |
| 23 | + |
| 24 | +func validateUUID(t *testing.T, u string) { |
| 25 | + var err error |
| 26 | + |
| 27 | + _, err = uuid.Parse(u) |
| 28 | + |
| 29 | + require.NoError(t, err) |
| 30 | +} |
| 31 | + |
| 32 | +func TestBox_Info(t *testing.T) { |
| 33 | + ctx := context.TODO() |
| 34 | + |
| 35 | + conn, err := tarantool.Connect(ctx, dialer, tarantool.Opts{}) |
| 36 | + require.NoError(t, err) |
| 37 | + |
| 38 | + info, err := box.By(conn).Info() |
| 39 | + require.NoError(t, err) |
| 40 | + |
| 41 | + // check all fields run correctly |
| 42 | + validateUUID(t, info.UUID) |
| 43 | + validateUUID(t, info.Cluster.UUID) |
| 44 | + |
| 45 | + require.NotEmpty(t, info.Version) |
| 46 | + // check that pid parsed correctly |
| 47 | + require.NotEqual(t, info.PID, 0) |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +func runTestMain(m *testing.M) int { |
| 52 | + instance, err := test_helpers.StartTarantool(test_helpers.StartOpts{ |
| 53 | + Dialer: dialer, |
| 54 | + InitScript: "config.lua", |
| 55 | + Listen: server, |
| 56 | + WaitStart: 100 * time.Millisecond, |
| 57 | + ConnectRetry: 10, |
| 58 | + RetryTimeout: 500 * time.Millisecond, |
| 59 | + }) |
| 60 | + defer test_helpers.StopTarantoolWithCleanup(instance) |
| 61 | + |
| 62 | + if err != nil { |
| 63 | + log.Printf("Failed to prepare test Tarantool: %s", err) |
| 64 | + return 1 |
| 65 | + } |
| 66 | + |
| 67 | + return m.Run() |
| 68 | +} |
| 69 | + |
| 70 | +func TestMain(m *testing.M) { |
| 71 | + code := runTestMain(m) |
| 72 | + os.Exit(code) |
| 73 | +} |
0 commit comments