-
Notifications
You must be signed in to change notification settings - Fork 18
/
options_test.go
129 lines (100 loc) · 3.08 KB
/
options_test.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// go-libdeluge v0.5.6 - a native deluge RPC client library
// Copyright (C) 2015~2023 gdm85 - https://github.com/gdm85/go-libdeluge/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
package delugeclient
import (
"testing"
)
var testOpts Options
func init() {
maxConns := 100
tVal := true
path := "some/path"
testOpts.MaxConnections = &maxConns
testOpts.AutoManaged = &tVal
testOpts.PreAllocateStorage = &tVal
testOpts.V2.Shared = &tVal
testOpts.DownloadLocation = &path
}
func TestNilOptionsEncode(t *testing.T) {
t.Parallel()
var o *Options
d := o.toDictionary(false)
if d.Length() != 0 {
t.Error("expected an empty dictionary")
}
}
func TestDefaultEncode(t *testing.T) {
testOptsWithDefaults := testOpts
fVal := false
testOptsWithDefaults.StopAtRatio = &fVal
d := testOptsWithDefaults.toDictionary(false)
m, err := d.Zip()
if err != nil {
t.Fatal(err)
}
if _, ok := m["stop_at_ratio"]; !ok {
t.Errorf("expected key %q not found", "stop_at_ratio")
}
}
func TestOptionsEncodeV1(t *testing.T) {
t.Parallel()
d := testOpts.toDictionary(false)
m, err := d.Zip()
if err != nil {
t.Fatal(err)
}
if _, ok := m["compact_allocation"]; !ok {
t.Errorf("expected key %q not found", "compact_allocation")
}
if _, ok := m["download_location"]; !ok {
t.Errorf("expected key %q not found", "download_location")
}
if _, ok := m["save_path"]; ok {
t.Errorf("unexpected key %q found", "save_path")
}
if _, ok := m["shared"]; ok {
t.Errorf("unexpected key %q found", "shared")
}
// a field never specified should not be encoded
if _, ok := m["max_upload_slots"]; ok {
t.Errorf("unexpected key %q found", "max_upload_slots")
}
}
func TestOptionsEncodeV2(t *testing.T) {
t.Parallel()
d := testOpts.toDictionary(true)
m, err := d.Zip()
if err != nil {
t.Fatal(err)
}
if _, ok := m["compact_allocation"]; ok {
t.Errorf("unexpected key %q found", "compact_allocation")
}
if _, ok := m["pre_allocate_storage"]; !ok {
t.Errorf("expected key %q not found", "pre_allocate_storage")
}
if _, ok := m["download_location"]; !ok {
t.Errorf("expected key %q not found", "download_location")
}
if _, ok := m["save_path"]; ok {
t.Errorf("unexpected key %q found", "save_path")
}
if _, ok := m["shared"]; !ok {
t.Errorf("expected key %q not found", "shared")
}
// a field never specified should not be encoded
if _, ok := m["max_upload_slots"]; ok {
t.Errorf("unexpected key %q found", "max_upload_slots")
}
}