Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/pkg/aria2/rpc/client_test.go
1562 views
1
package rpc
2
3
import (
4
"context"
5
"testing"
6
"time"
7
)
8
9
func TestHTTPAll(t *testing.T) {
10
const targetURL = "https://nodejs.org/dist/index.json"
11
rpc, err := New(context.Background(), "http://localhost:6800/jsonrpc", "", time.Second, &DummyNotifier{})
12
if err != nil {
13
t.Fatal(err)
14
}
15
defer rpc.Close()
16
g, err := rpc.AddURI([]string{targetURL})
17
if err != nil {
18
t.Fatal(err)
19
}
20
println(g)
21
if _, err = rpc.TellActive(); err != nil {
22
t.Error(err)
23
}
24
if _, err = rpc.PauseAll(); err != nil {
25
t.Error(err)
26
}
27
if _, err = rpc.TellStatus(g); err != nil {
28
t.Error(err)
29
}
30
if _, err = rpc.GetURIs(g); err != nil {
31
t.Error(err)
32
}
33
if _, err = rpc.GetFiles(g); err != nil {
34
t.Error(err)
35
}
36
if _, err = rpc.GetPeers(g); err != nil {
37
t.Error(err)
38
}
39
if _, err = rpc.TellActive(); err != nil {
40
t.Error(err)
41
}
42
if _, err = rpc.TellWaiting(0, 1); err != nil {
43
t.Error(err)
44
}
45
if _, err = rpc.TellStopped(0, 1); err != nil {
46
t.Error(err)
47
}
48
if _, err = rpc.GetOption(g); err != nil {
49
t.Error(err)
50
}
51
if _, err = rpc.GetGlobalOption(); err != nil {
52
t.Error(err)
53
}
54
if _, err = rpc.GetGlobalStat(); err != nil {
55
t.Error(err)
56
}
57
if _, err = rpc.GetSessionInfo(); err != nil {
58
t.Error(err)
59
}
60
if _, err = rpc.Remove(g); err != nil {
61
t.Error(err)
62
}
63
if _, err = rpc.TellActive(); err != nil {
64
t.Error(err)
65
}
66
}
67
68
func TestWebsocketAll(t *testing.T) {
69
const targetURL = "https://nodejs.org/dist/index.json"
70
rpc, err := New(context.Background(), "ws://localhost:6800/jsonrpc", "", time.Second, &DummyNotifier{})
71
if err != nil {
72
t.Fatal(err)
73
}
74
defer rpc.Close()
75
g, err := rpc.AddURI([]string{targetURL})
76
if err != nil {
77
t.Fatal(err)
78
}
79
println(g)
80
if _, err = rpc.TellActive(); err != nil {
81
t.Error(err)
82
}
83
if _, err = rpc.PauseAll(); err != nil {
84
t.Error(err)
85
}
86
if _, err = rpc.TellStatus(g); err != nil {
87
t.Error(err)
88
}
89
if _, err = rpc.GetURIs(g); err != nil {
90
t.Error(err)
91
}
92
if _, err = rpc.GetFiles(g); err != nil {
93
t.Error(err)
94
}
95
if _, err = rpc.GetPeers(g); err != nil {
96
t.Error(err)
97
}
98
if _, err = rpc.TellActive(); err != nil {
99
t.Error(err)
100
}
101
if _, err = rpc.TellWaiting(0, 1); err != nil {
102
t.Error(err)
103
}
104
if _, err = rpc.TellStopped(0, 1); err != nil {
105
t.Error(err)
106
}
107
if _, err = rpc.GetOption(g); err != nil {
108
t.Error(err)
109
}
110
if _, err = rpc.GetGlobalOption(); err != nil {
111
t.Error(err)
112
}
113
if _, err = rpc.GetGlobalStat(); err != nil {
114
t.Error(err)
115
}
116
if _, err = rpc.GetSessionInfo(); err != nil {
117
t.Error(err)
118
}
119
if _, err = rpc.Remove(g); err != nil {
120
t.Error(err)
121
}
122
if _, err = rpc.TellActive(); err != nil {
123
t.Error(err)
124
}
125
}
126
127