/
test.go
66 lines (58 loc) · 1.12 KB
/
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
package main
import (
"fmt"
"github.com/DoG-peer/gobou/notify"
"github.com/DoG-peer/gobou/utils"
"os"
"os/exec"
"path/filepath"
"time"
)
// Test runs test for gobou plugin developer
func Test() {
p, _ := os.Getwd()
name := filepath.Base(p)
fmt.Println(p)
err := exec.Command("go", "build").Run()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Finish build")
mesChan := make(chan gobou.Message)
go func() {
time.Sleep(10 * time.Second)
close(mesChan)
}()
plug := PluginManager{
configFile: filepath.Join(p, "test_config.json"),
name: name,
path: filepath.Join(p, name),
messageChannel: mesChan,
}
plug.Start()
defer plug.Stop()
err = plug.Configure()
if err != nil {
fmt.Println(err, "config")
return
}
fmt.Println("Finish configure")
go func() {
err = plug.Main()
if err != nil {
fmt.Println(err, "plugin")
return
}
plug.Notify()
}()
for mes := range mesChan {
if !mes.NotifyMessage.IsNone() {
notify.Notify(mes.NotifyMessage.Text)
}
if !mes.StdoutMessage.IsNone() {
fmt.Println(mes.StdoutMessage.Text)
}
}
fmt.Println("Finish")
}