-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinfer_test.go
65 lines (44 loc) · 1.56 KB
/
infer_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
package infer
import (
"testing"
"log"
"time"
"github.com/jack139/go-infer/types"
"github.com/jack139/go-infer/cli"
)
/* 定义模型相关参数和方法 */
type EchoModel struct{ types.Base }
func (x *EchoModel) ApiPath() string {
return "/api/echo"
}
func (x *EchoModel) Init() error {
log.Println("Model Init()", x.ApiPath())
return nil
}
func (x *EchoModel) ApiEntry(reqData *map[string]interface{}) (*map[string]interface{}, error) {
log.Println("Model ApiEntry()", x.ApiPath())
log.Println("request data: ", *reqData)
return reqData, nil
//return &map[string]interface{}{"code":9999}, fmt.Errorf("parameters error test") // 错误返回: 错误代码,错误信息
}
func (x *EchoModel) Infer(requestId string, reqData *map[string]interface{}) (*map[string]interface{}, error) {
log.Println("Model Infer()", x.ApiPath())
log.Println("requestId", requestId, "infer return data: ", reqData)
time.Sleep(1 * time.Second) // 延时,模拟推理业务
return reqData, nil
//return &map[string]interface{}{"code":9998}, fmt.Errorf("infer error test") // 错误返回: 错误代码,错误信息
}
func TestHttp(t *testing.T) {
t.Log("test HTTP service")
types.ModelList = append(types.ModelList, &EchoModel{})
// 启动 http
cli.HttpCmd.SetArgs([]string{"--yaml=config/settings.yaml"})
cli.HttpCmd.Execute()
}
func TestServer(t *testing.T) {
t.Log("test Server")
types.ModelList = append(types.ModelList, &EchoModel{})
// 启动 分发服务
cli.ServerCmd.SetArgs([]string{"0", "--yaml=config/settings.yaml"})
cli.ServerCmd.Execute()
}