-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathclient_test.go
More file actions
72 lines (62 loc) · 1.9 KB
/
client_test.go
File metadata and controls
72 lines (62 loc) · 1.9 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
package main
import "testing"
func TestIsSupportClient(t *testing.T) {
oldClient := currentClient
defer func() { currentClient = oldClient }()
currentClient = nil
if IsSupportClient() {
t.Fatalf("IsSupportClient() should be false when currentClient is nil")
}
currentClient = &QBClient{}
if !IsSupportClient() {
t.Fatalf("IsSupportClient() should be true when currentClient exists")
}
}
func TestIsBanPort(t *testing.T) {
oldClientType := currentClientType
oldFlag := qB_useNewBanPeersMethod
defer func() {
currentClientType = oldClientType
qB_useNewBanPeersMethod = oldFlag
}()
currentClientType = "qBittorrent"
qB_useNewBanPeersMethod = true
if !IsBanPort() {
t.Fatalf("IsBanPort() should be true for qBittorrent with new ban method")
}
currentClientType = "Transmission"
if IsBanPort() {
t.Fatalf("IsBanPort() should be false for non-qBittorrent client")
}
}
func TestSubmitBlockPeer_NilInput(t *testing.T) {
if !SubmitBlockPeer(nil) {
t.Fatalf("SubmitBlockPeer(nil) should return true")
}
}
func TestTrTorrentToTorrent(t *testing.T) {
torrent := trTorrentToTorrent(Tr_TorrentStruct{
InfoHash: "hash-a",
TotalSize: 12345,
Private: true,
Peers: []Tr_PeerStruct{
{IP: "1.1.1.1", Port: 51413, Client: "peer-a", Progress: 0.5, DlSpeed: 1, UpSpeed: 2, IsUploading: true},
{IP: "2.2.2.2", Port: 51414, Client: "peer-b", Progress: 0.2, DlSpeed: 3, UpSpeed: 4, IsUploading: false},
},
})
if torrent.Hash != "hash-a" {
t.Fatalf("Hash=%q, want hash-a", torrent.Hash)
}
if torrent.Tracker != "Private" {
t.Fatalf("Tracker=%q, want Private", torrent.Tracker)
}
if torrent.LeechCount != 1 {
t.Fatalf("LeechCount=%d, want 1", torrent.LeechCount)
}
if len(torrent.Peers) != 2 {
t.Fatalf("len(Peers)=%d, want 2", len(torrent.Peers))
}
if torrent.Peers[0].Downloaded != -1 || torrent.Peers[0].Uploaded != -1 {
t.Fatalf("Transmission peer traffic defaults should remain -1")
}
}