-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy patharia2c_test.go
More file actions
91 lines (86 loc) · 2.01 KB
/
aria2c_test.go
File metadata and controls
91 lines (86 loc) · 2.01 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"flag"
"github.com/hanjm/log"
"syscall"
"testing"
"time"
)
func withTestEnv(fn func()) {
flag.Parse()
pid := Aria2Worker("download")
log.Infof("aria2c pid is %d", pid)
time.Sleep(time.Second)
defer syscall.Kill(pid, syscall.SIGQUIT)
fn()
}
func TestAria2cRPCClient_AddURI(t *testing.T) {
t.Run("addCorrectURL", func(t *testing.T) {
withTestEnv(
func() {
rpcClient := NewAria2cRPCClient()
taskGID, err := rpcClient.AddURI("http://github.com")
if err != nil {
t.Fatal(err)
}
t.Logf("taskGID:%s", taskGID)
})
})
}
func TestAria2cRPCClient_TellStatus(t *testing.T) {
t.Run("TellHTTPStatus", func(t *testing.T) {
withTestEnv(
func() {
rpcClient := NewAria2cRPCClient()
taskGID, err := rpcClient.AddURI("https://github.com/hashicorp/consul/archive/v0.9.3.tar.gz")
if err != nil {
t.Fatal(err)
}
t.Logf("taskGID:%s", taskGID)
for i := 0; i < 10; i++ {
time.Sleep(time.Microsecond * 200)
resp, err := rpcClient.TellStatus(taskGID)
if err != nil {
t.Fatal(err)
}
t.Logf("status:%+v", resp)
}
})
})
t.Run("TellMagnetStatus", func(t *testing.T) {
withTestEnv(
func() {
rpcClient := NewAria2cRPCClient()
taskGID, err := rpcClient.AddURI("magnet:?xt=urn:btih:09c4beba230a770051207d07a8fb76cf43477523")
if err != nil {
t.Fatal(err)
}
t.Logf("taskGID:%s", taskGID)
for i := 0; i < 10; i++ {
time.Sleep(time.Microsecond * 200)
resp, err := rpcClient.TellStatus(taskGID)
if err != nil {
t.Fatal(err)
}
t.Logf("status:%+v", resp)
}
})
})
}
func TestAria2cRPCClient_RemoveDownloadResult(t *testing.T) {
withTestEnv(
func() {
rpcClient := NewAria2cRPCClient()
taskGID, err := rpcClient.AddURI("http://github.com")
if err != nil {
t.Fatal(err)
}
t.Logf("taskGID:%s", taskGID)
// wait download complete
time.Sleep(time.Second * 5)
err = rpcClient.RemoveDownloadResult(taskGID)
if err != nil {
t.Fatal(err)
}
})
}