-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager_test.go
More file actions
67 lines (50 loc) · 1.39 KB
/
manager_test.go
File metadata and controls
67 lines (50 loc) · 1.39 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
package pluginmanager_test
import (
"testing"
"github.com/hyperscale-stack/pluginmanager"
plug "github.com/hyperscale-stack/pluginmanager/demo/pkg/plugin"
"github.com/stretchr/testify/assert"
)
type Authentification interface {
Authentificate(username, password string) (bool, error)
}
var _ Authentification = (*MyPlugin)(nil)
// plugin test
type MyPlugin struct {
}
func (p *MyPlugin) Authentificate(username, password string) (bool, error) {
return true, nil
}
func TestPluginManager(t *testing.T) {
pm := pluginmanager.New[Authentification]()
plugin := &pluginmanager.Plugin[Authentification]{
Name: "test",
Instance: &MyPlugin{},
}
err := pm.Register(plugin)
assert.NoError(t, err)
p, err := pm.Get("test")
assert.NoError(t, err)
assert.NotNil(t, p)
assert.Implements(t, (*Authentification)(nil), p)
assert.Equal(t, p, plugin.Instance)
p, err = pm.Get("test2")
assert.Error(t, err)
assert.Nil(t, p)
err = pm.Register(plugin)
assert.Error(t, err)
}
func TestPluginManagerWithFile(t *testing.T) {
pm := pluginmanager.New[plug.Authentification]()
err := pm.RegisterFromFile("test.plugin.so")
assert.NoError(t, err)
p, err := pm.Get("test")
assert.NoError(t, err)
assert.NotNil(t, p)
assert.Implements(t, (*plug.Authentification)(nil), p)
p, err = pm.Get("test2")
assert.Error(t, err)
assert.Nil(t, p)
err = pm.RegisterFromFile("test.plugin.so")
assert.Error(t, err)
}