-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_test.go
More file actions
178 lines (141 loc) · 5.67 KB
/
Copy pathengine_test.go
File metadata and controls
178 lines (141 loc) · 5.67 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package client_test
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
// fakeEngine records the most recent call to each delegated method so the
// dispatcher tests can assert *Rocks forwards verbatim to r.engine. Every
// method returns a sentinel value the test can recognize.
type fakeEngine struct {
installName string
installOpts client.InstallOpts
buildSpec string
buildOpts client.BuildOpts
makeOpts client.MakeOpts
packTarget string
packOpts client.PackOpts
unpackArchive string
unpackDest string
err error
}
func (f *fakeEngine) Install(_ context.Context, name string, opts client.InstallOpts) error {
f.installName = name
f.installOpts = opts
return f.err
}
func (f *fakeEngine) Build(_ context.Context, specPath string, opts client.BuildOpts) error {
f.buildSpec = specPath
f.buildOpts = opts
return f.err
}
func (f *fakeEngine) Make(_ context.Context, opts client.MakeOpts) error {
f.makeOpts = opts
return f.err
}
func (f *fakeEngine) Pack(_ context.Context, target string, opts client.PackOpts) (string, error) {
f.packTarget = target
f.packOpts = opts
return "packed-" + target, f.err
}
func (f *fakeEngine) Unpack(_ context.Context, archive, destDir string) error {
f.unpackArchive = archive
f.unpackDest = destDir
return f.err
}
// The thirteen stubs are unused by the dispatcher tests but required to
// satisfy the Engine interface.
func (f *fakeEngine) Remove(context.Context, string, client.RemoveOpts) error { return nil }
func (f *fakeEngine) Purge(context.Context, client.PurgeOpts) error { return nil }
func (f *fakeEngine) Search(context.Context, string, client.SearchOpts) ([]client.SearchResult, error) {
return nil, nil
}
func (f *fakeEngine) Download(context.Context, string, client.DownloadOpts) (string, error) {
return "", nil
}
func (f *fakeEngine) Lint(context.Context, string, client.LintOpts) error { return nil }
func (f *fakeEngine) NewVersion(context.Context, string, client.NewVersionOpts) (string, error) {
return "", nil
}
func (f *fakeEngine) WriteRockspec(context.Context, string, client.WriteRockspecOpts) (string, error) {
return "", nil
}
func (f *fakeEngine) Doc(context.Context, string, client.DocOpts) error { return nil }
func (f *fakeEngine) Test(context.Context, string, client.TestOpts) error { return nil }
func (f *fakeEngine) Config(context.Context, client.ConfigOpts) (string, error) {
return "", nil
}
func (f *fakeEngine) Upload(context.Context, string, client.UploadOpts) error { return nil }
func (f *fakeEngine) InitProject(context.Context, client.InitProjectOpts) error { return nil }
func (f *fakeEngine) Admin(context.Context, string, []string, client.AdminOpts) error {
return nil
}
func TestRocksInstall_DelegatesToEngine(t *testing.T) {
t.Parallel()
fake := &fakeEngine{}
r := client.NewRocksWithEngine(fake)
opts := client.InstallOpts{Version: "1.2.3", Servers: []string{"https://example/"}, Deps: client.DepsNone}
require.NoError(t, r.Install(context.Background(), "foo", opts), "Install")
assert.Equal(t, "foo", fake.installName, "engine.Install name")
// InstallOpts contains a []string field; require.Equal deep-compares slices.
assert.Equal(t, opts, fake.installOpts, "engine.Install opts")
}
func TestRocksBuild_DelegatesToEngine(t *testing.T) {
t.Parallel()
fake := &fakeEngine{}
r := client.NewRocksWithEngine(fake)
opts := client.BuildOpts{Keep: true}
require.NoError(t, r.Build(context.Background(), "foo.rockspec", opts), "Build")
assert.Equal(t, "foo.rockspec", fake.buildSpec, "engine.Build specPath")
assert.Equal(t, opts, fake.buildOpts, "engine.Build opts")
}
func TestRocksMake_DelegatesToEngine(t *testing.T) {
t.Parallel()
fake := &fakeEngine{}
r := client.NewRocksWithEngine(fake)
opts := client.MakeOpts{RockspecPath: "x.rockspec"}
require.NoError(t, r.Make(context.Background(), opts), "Make")
assert.Equal(t, opts, fake.makeOpts, "engine.Make opts")
}
func TestRocksPack_DelegatesToEngine(t *testing.T) {
t.Parallel()
fake := &fakeEngine{}
r := client.NewRocksWithEngine(fake)
opts := client.PackOpts{SrcOnly: true}
got, err := r.Pack(context.Background(), "foo", opts)
require.NoError(t, err, "Pack")
assert.Equal(t, "foo", fake.packTarget, "engine.Pack target")
assert.Equal(t, opts, fake.packOpts, "engine.Pack opts")
assert.Equal(t, "packed-foo", got, "Pack returned value (engine result must pass through)")
}
func TestRocksUnpack_DelegatesToEngine(t *testing.T) {
t.Parallel()
fake := &fakeEngine{}
r := client.NewRocksWithEngine(fake)
require.NoError(t, r.Unpack(context.Background(), "a.rock", "/dest"), "Unpack")
assert.Equal(t, "a.rock", fake.unpackArchive, "engine.Unpack archive")
assert.Equal(t, "/dest", fake.unpackDest, "engine.Unpack destDir")
}
func TestNew_DefaultBackendIsNative(t *testing.T) {
t.Parallel()
r, err := client.New(rocks.Config{Tree: t.TempDir()})
require.NoError(t, err, "New")
_, ok := r.Engine().(*client.NativeEngine)
assert.True(t, ok, "default engine = %T, want *nativeEngine", r.Engine())
}
func TestNew_WithBackendLua(t *testing.T) {
t.Parallel()
r, err := client.New(rocks.Config{Tree: t.TempDir()}, client.WithBackend(client.BackendLua))
require.NoError(t, err, "New")
// The lua backend swaps the engine to luaEngine; assert the concrete type.
_, ok := r.Engine().(*client.LuaEngine)
assert.True(t, ok, "lua engine = %T, want *luaEngine", r.Engine())
}
// guard: fakeEngine must satisfy Engine.
var _ client.Engine = (*fakeEngine)(nil)
// guard: errors.Is wiring for ErrNotImplemented compiles against rocks.
var _ = errors.Is(rocks.ErrNotImplemented, rocks.ErrNotImplemented)