mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 09:30:27 +00:00
cgo invoke params
This commit is contained in:
1 parent
4b4c03fd90
commit
63296f6950
5 files changed
+29
-36
No files matched your search
+14
-17
@@ -10,26 +10,20 @@ import (
|
||||
var instance, _ = Create(nil)
|
||||
|
||||
func TestInvoke(t *testing.T) {
|
||||
doTestInvoke(t, "Info", []any{})
|
||||
doTestInvoke(t, "GetTasks", nil)
|
||||
doTestInvoke(t, "GetTasks", []any{})
|
||||
doTestInvoke(t, "GetTasks", []any{nil})
|
||||
doTestInvoke(t, "GetTasks", []any{&download.TaskFilter{}})
|
||||
doTestInvoke(t, "Info", []any{}, model.CodeOk)
|
||||
doTestInvoke(t, "Info1", []any{}, model.CodeError)
|
||||
doTestInvoke(t, "CreateTask", []any{nil}, model.CodeError)
|
||||
doTestInvoke(t, "GetTasks", nil, model.CodeError)
|
||||
doTestInvoke(t, "GetTasks", []any{}, model.CodeError)
|
||||
doTestInvoke(t, "GetTasks", []any{"{abc:123"}, model.CodeError)
|
||||
doTestInvoke(t, "GetTasks", []any{&download.TaskFilter{}}, model.CodeOk)
|
||||
doTestInvoke(t, "SwitchExtension", []any{"test", &model.SwitchExtension{Status: true}}, model.CodeError)
|
||||
}
|
||||
|
||||
func doTestInvoke(t *testing.T, method string, params []any) *model.Result[any] {
|
||||
reqParams := make([]string, len(params))
|
||||
for i, p := range params {
|
||||
bytes, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reqParams[i] = string(bytes)
|
||||
}
|
||||
|
||||
func doTestInvoke(t *testing.T, method string, params []any, expectCode model.RespCode) {
|
||||
result := Invoke(instance, &Request{
|
||||
Method: method,
|
||||
Params: reqParams,
|
||||
Params: params,
|
||||
})
|
||||
buf, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
@@ -40,5 +34,8 @@ func doTestInvoke(t *testing.T, method string, params []any) *model.Result[any]
|
||||
if err := json.Unmarshal(buf, &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return &res
|
||||
|
||||
if res.Code != expectCode {
|
||||
t.Fatalf("Invoke method [%s] failed, expect code [%d], got [%d], msg: %s", method, expectCode, res.Code, res.Msg)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user