generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager_test.go
48 lines (38 loc) · 976 Bytes
/
manager_test.go
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
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package plugins
import (
"path"
"plugin"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
for _, path := range []string{"foo", "bar"} {
m := New(path)
assert.Equal(t, path, m.Path)
}
}
func TestManagerOpen(t *testing.T) {
dir := "testdata"
m := New(dir)
for _, name := range []string{"foo.so", "bar.so"} {
expectedP, expectedErr := plugin.Open(path.Join(dir, name))
p, err := m.Open(name)
assert.Equal(t, expectedErr, err)
assert.Equal(t, expectedP, p)
}
}
func TestManagerLookup(t *testing.T) {
dir := "testdata"
m := New(dir)
_, err := m.Lookup("nil", "Foo")
assert.NotNil(t, err)
_, err = m.Lookup("foo.so", "Bar")
assert.NotNil(t, err)
sym, err := m.Lookup("foo.so", "Foo")
assert.Nil(t, err)
f := sym.(func() string)
assert.Equal(t, "Bar", f())
}