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

Function LoadPluginForTest

pkg/plugin/helper.go:64–115  ·  view source on GitHub ↗

LoadPluginForTest loads a test plugin with given onGeneralEvent callback.

(t *testing.T, onGeneralEvent func(context.Context, *variable.SessionVars, GeneralEvent, string))

Source from the content-addressed store, hash-verified

62
63// LoadPluginForTest loads a test plugin with given onGeneralEvent callback.
64func LoadPluginForTest(t *testing.T, onGeneralEvent func(context.Context, *variable.SessionVars, GeneralEvent, string)) {
65 ctx := context.Background()
66 pluginName := "audit_test"
67 pluginVersion := uint16(1)
68 pluginSign := pluginName + "-" + strconv.Itoa(int(pluginVersion))
69
70 cfg := Config{
71 Plugins: []string{pluginSign},
72 PluginDir: "",
73 EnvVersion: map[string]uint16{"go": 1112},
74 }
75
76 validate := func(_ context.Context, _ *Manifest) error {
77 return nil
78 }
79 onInit := func(_ context.Context, _ *Manifest) error {
80 return nil
81 }
82 onShutdown := func(_ context.Context, _ *Manifest) error {
83 return nil
84 }
85 onConnectionEvent := func(_ context.Context, _ ConnectionEvent, _ *variable.ConnectionInfo) error {
86 return nil
87 }
88
89 // setup load test hook.
90 loadOne := func(_ *Plugin, _ string, _ ID) (manifest func() *Manifest, err error) {
91 return func() *Manifest {
92 m := &AuditManifest{
93 Manifest: Manifest{
94 Kind: Audit,
95 Name: pluginName,
96 Version: pluginVersion,
97 OnInit: onInit,
98 OnShutdown: onShutdown,
99 Validate: validate,
100 },
101 OnGeneralEvent: onGeneralEvent,
102 OnConnectionEvent: onConnectionEvent,
103 }
104 return ExportManifest(m)
105 }, nil
106 }
107 SetTestHook(loadOne)
108
109 // trigger load.
110 err := Load(ctx, cfg)
111 require.NoErrorf(t, err, "load plugin [%s] fail, error [%s]\n", pluginSign, err)
112
113 err = Init(ctx, cfg)
114 require.NoErrorf(t, err, "init plugin [%s] fail, error [%s]\n", pluginSign, err)
115}

Callers 3

TestAuditLogNormalFunction · 0.92
TestAuditPluginRetryingFunction · 0.92

Calls 4

ExportManifestFunction · 0.85
SetTestHookFunction · 0.85
LoadFunction · 0.85
InitFunction · 0.70

Tested by 3

TestAuditLogNormalFunction · 0.74
TestAuditPluginRetryingFunction · 0.74