This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_test.go
94 lines (76 loc) · 1.73 KB
/
plugin_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
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
package pluginfx
import (
"errors"
"testing"
"github.com/stretchr/testify/suite"
)
type PluginSuite struct {
PluginfxSuite
}
func (suite *PluginSuite) TestOpen() {
suite.Run("Nosuch", func() {
p, err := Open("nosuch")
suite.Nil(p)
suite.openError("nosuch", err)
})
suite.Run("Sample", func() {
p := suite.openSuccess(Open(samplePath))
v, err := p.Lookup("Value")
suite.NoError(err)
suite.Require().NotNil(v)
suite.Equal(12, *v.(*int))
})
}
func (suite *PluginSuite) TestLookup() {
suite.Run("SymbolMap", func() {
suite.Run("Found", func() {
var sm SymbolMap
sm.Set("Foo", 12)
v, err := Lookup(&sm, "Foo")
suite.NoError(err)
suite.Require().NotNil(v)
suite.Equal(12, *v.(*int))
})
suite.Run("Missing", func() {
var sm SymbolMap
v, err := Lookup(&sm, "Foo")
suite.Nil(v)
mse := suite.missingSymbolError("Foo", err)
suite.NoError(mse.Err)
})
})
suite.Run("Sample", func() {
suite.Run("Found", func() {
p := suite.openSuccess(Open(samplePath))
v, err := Lookup(p, "Value")
suite.NoError(err)
suite.Require().NotNil(v)
suite.Equal(12, *v.(*int))
})
suite.Run("Missing", func() {
p := suite.openSuccess(Open(samplePath))
v, err := Lookup(p, "Nosuch")
suite.Nil(v)
mse := suite.missingSymbolError("Nosuch", err)
suite.Error(mse.Err)
})
})
}
func (suite *PluginSuite) TestIsMissingSymbolError() {
suite.Run("Nil", func() {
suite.False(IsMissingSymbolError(nil))
})
suite.Run("DifferentError", func() {
suite.False(
IsMissingSymbolError(errors.New("some error")),
)
})
suite.Run("Missing", func() {
suite.True(
IsMissingSymbolError(new(MissingSymbolError)),
)
})
}
func TestPlugin(t *testing.T) {
suite.Run(t, new(PluginSuite))
}