marketing-plugin/instance/instance_test.go

95 lines
2.0 KiB
Go

package instance
import (
"context"
"encoding/json"
"gitea.cdlsxd.cn/zhouyonggao/marketing-plugin/manage"
"gitea.cdlsxd.cn/zhouyonggao/marketing-plugin/proto"
"testing"
"time"
)
func config() []byte {
type Config struct {
AppId string `json:"app_id"`
AppKey string `json:"app_key"`
BaseUri string `json:"base_uri"`
NotifyUrl string `json:"notify_url"`
}
c := &Config{
AppId: "23329",
AppKey: "8db16e8cc8363ed4eb4c14f9520bcc32",
BaseUri: "http://test.openapi.1688sup.cn",
NotifyUrl: "http://test.openapi.1688sup.cn",
}
marshal, _ := json.Marshal(c)
return marshal
}
func TestLoad(t *testing.T) {
// 初始化插件库,加载插件库
load := []*manage.Config{
{
Cmd: "pkg/zltx.so",
Tag: "zltx",
Version: 1,
CookieKey: "k",
CookieValue: "2",
Timeout: time.Second * 10,
},
}
if err := manage.Load(load); err != nil {
t.Errorf("Load() error = %v", err)
return
}
// 调用插件
tag := "zltx"
// 下单
request := &proto.OrderRequest{
Config: []byte(`{}`),
Order: &proto.OrderRequest_Order{
OrderNo: "zltx_" + time.Now().Format("20060102150405"),
Account: "18666666666",
Extra: nil,
},
Product: &proto.OrderRequest_Product{
ProductNo: "106",
Extra: []byte(`{}`),
},
}
result, err := Order(context.Background(), tag, request)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
t.Logf("Order() result = %v", result)
// 查询
req := &proto.QueryRequest{
Config: nil,
Order: &proto.QueryRequest_Order{
OrderNo: request.Order.OrderNo,
},
}
res, err := Query(context.Background(), tag, req)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
t.Logf("Query() result = %v", res)
// 回调
notify := &proto.NotifyRequest{
Config: nil,
Headers: []byte(`{"k":"v"}`),
Queries: []byte(`{"k":"v"}`),
Body: []byte(`{"k":"v"}`),
}
n, err := Notify(context.Background(), tag, notify)
if err != nil {
t.Errorf("Order() error = %v", err)
return
}
t.Logf("Notify() result = %v", n)
}