-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua_test.go
More file actions
83 lines (64 loc) · 2.07 KB
/
Copy pathlua_test.go
File metadata and controls
83 lines (64 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package client_test
import (
"sync"
"testing"
"github.com/stretchr/testify/require"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
"github.com/tarantool/go-luarocks/manif"
lua "github.com/yuin/gopher-lua"
)
// luaEngine must satisfy the Engine contract (mirrors the nativeEngine
// assertion in native_test.go); the New() wiring relies on this.
var _ client.Engine = (*client.LuaEngine)(nil)
// luaTestCfg returns a Config with the required Tree and a WorkingDir, both
// pointing at a fresh temp dir, plus a Tarantool prefix for env-override
// assertions.
func luaTestCfg(t *testing.T) rocks.Config {
t.Helper()
dir := t.TempDir()
return rocks.Config{
Tree: dir,
WorkingDir: dir,
}
}
func TestLuaEngine_BootSucceeds_NoOp(t *testing.T) {
t.Parallel()
e := client.NewLuaEngine(luaTestCfg(t), manif.FileStore{}, nil)
require.NoError(t, e.Boot(), "boot")
require.NotNil(t, e.LState(), "boot did not cache an LState")
}
func TestLuaEngine_OsGetenvOverride(t *testing.T) {
t.Parallel()
cfg := luaTestCfg(t)
cfg.Tarantool.Prefix = "/test-prefix"
e := client.NewLuaEngine(cfg, manif.FileStore{}, nil)
require.NoError(t, e.Boot(), "boot")
require.NoError(t, e.LState().DoString("return require('luarocks.core.hardcoded').PREFIX"), "probe DoString")
got := e.LState().Get(-1)
e.LState().Pop(1)
require.True(t, got.Type() == lua.LTString && got.String() == "/test-prefix",
"hardcoded.PREFIX = %v (%s); want \"/test-prefix\"", got, got.Type())
}
func TestLuaEngine_WrapperExec_Help(t *testing.T) {
t.Parallel()
e := client.NewLuaEngine(luaTestCfg(t), manif.FileStore{}, nil)
require.NoError(t, e.Call([]string{"help"}), "call help")
}
func TestLuaEngine_MutexSerializes(t *testing.T) {
t.Parallel()
e := client.NewLuaEngine(luaTestCfg(t), manif.FileStore{}, nil)
var wg sync.WaitGroup
errs := make([]error, 2)
for i := range errs {
wg.Add(1)
go func(idx int) {
defer wg.Done()
errs[idx] = e.Call([]string{"help"})
}(i)
}
wg.Wait()
for i, err := range errs {
require.NoError(t, err, "concurrent call %d", i)
}
}