-
Notifications
You must be signed in to change notification settings - Fork 8
/
go_plugin_test.go
53 lines (43 loc) · 1.04 KB
/
go_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
//go:build linux || freebsd || darwin
// +build linux freebsd darwin
// go plugin doesn't support windows
package funplugin
import (
"fmt"
"os"
"testing"
"github.com/httprunner/funplugin/myexec"
"github.com/stretchr/testify/assert"
)
func buildGoPlugin() {
fmt.Println("[setup] build go plugin")
// flag -race is necessary in order to be consistent with go test
err := myexec.RunCommand("go", "build", "-buildmode=plugin", "-race",
"-o=debugtalk.so", "fungo/examples/debugtalk.go")
if err != nil {
panic(err)
}
}
func removeGoPlugin() {
fmt.Println("[teardown] remove go plugin")
os.Remove("debugtalk.so")
}
func TestCallPluginFunction(t *testing.T) {
buildGoPlugin()
defer removeGoPlugin()
plugin, err := Init("debugtalk.so", WithDebugLogger(true))
if err != nil {
t.Fatal(err)
}
if !assert.True(t, plugin.Has("Concatenate")) {
t.Fail()
}
// call function with arguments
result, err := plugin.Call("Concatenate", "1", 2, "3.14")
if !assert.NoError(t, err) {
t.Fail()
}
if !assert.Equal(t, "123.14", result) {
t.Fail()
}
}