MCPcopy
hub / github.com/pingcap/tidb / TestLoadPluginSkipError

Function TestLoadPluginSkipError

pkg/plugin/plugin_test.go:178–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestLoadPluginSkipError(t *testing.T) {
179 ctx := context.Background()
180
181 pluginName := "tplugin"
182 pluginVersion := uint16(1)
183 pluginSign := pluginName + "-" + strconv.Itoa(int(pluginVersion))
184
185 cfg := Config{
186 Plugins: []string{pluginSign, pluginSign, "notExists-2"},
187 PluginDir: "",
188 EnvVersion: map[string]uint16{"go": 1112},
189 SkipWhenFail: true,
190 }
191
192 // setup load test hook.
193 SetTestHook(func(plugin *Plugin, dir string, pluginID ID) (manifest func() *Manifest, err error) {
194 return func() *Manifest {
195 m := &AuditManifest{
196 Manifest: Manifest{
197 Kind: Audit,
198 Name: pluginName,
199 Version: pluginVersion,
200 OnInit: func(ctx context.Context, manifest *Manifest) error {
201 return io.EOF
202 },
203 OnShutdown: func(ctx context.Context, manifest *Manifest) error {
204 return io.EOF
205 },
206 Validate: func(ctx context.Context, manifest *Manifest) error {
207 return io.EOF
208 },
209 },
210 OnGeneralEvent: func(ctx context.Context, sctx *variable.SessionVars, event GeneralEvent, cmd string) {
211 },
212 }
213 return ExportManifest(m)
214 }, nil
215 })
216 defer func() {
217 testHook = nil
218 }()
219
220 // trigger load.
221 err := Load(ctx, cfg)
222 require.NoError(t, err)
223
224 err = Init(ctx, cfg)
225 require.NoError(t, err)
226 require.False(t, IsEnable(Audit))
227
228 // load all.
229 ps := GetAll()
230 require.Len(t, ps, 1)
231
232 // find plugin by type and name
233 p := Get(Audit, "tplugin")
234 require.NotNil(t, p)
235 p = Get(Audit, "tplugin2")

Callers

nothing calls this directly

Calls 13

SetTestHookFunction · 0.85
ExportManifestFunction · 0.85
LoadFunction · 0.85
IsEnableFunction · 0.85
GetAllFunction · 0.85
GetFunction · 0.85
getByNameFunction · 0.85
ForeachPluginFunction · 0.85
ShutdownFunction · 0.85
NotNilMethod · 0.80
InitFunction · 0.70
LenMethod · 0.65

Tested by

no test coverage detected