-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
126 lines (107 loc) · 2.83 KB
/
config_test.go
File metadata and controls
126 lines (107 loc) · 2.83 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
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
package imx
import (
"testing"
"time"
)
func TestWithHTTPTimeout(t *testing.T) {
cfg := config{}
opt := WithHTTPTimeout(60 * time.Second)
opt(&cfg)
if cfg.HTTPTimeout != 60*time.Second {
t.Errorf("WithHTTPTimeout() HTTPTimeout = %v, want 60s", cfg.HTTPTimeout)
}
}
func TestDefaultConfig(t *testing.T) {
cfg := defaultConfig()
if cfg.HTTPTimeout != 30*time.Second {
t.Errorf("defaultConfig() HTTPTimeout = %v, want 30s", cfg.HTTPTimeout)
}
}
func TestConfig_Defaults(t *testing.T) {
cfg := config{}
if cfg.HTTPTimeout != 0 {
t.Errorf("Default HTTPTimeout = %v, want 0", cfg.HTTPTimeout)
}
}
func TestWithHTTPTimeout_Negative(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for negative HTTPTimeout")
} else if msg, ok := r.(string); ok {
if msg != "imx: HTTPTimeout must be non-negative" {
t.Errorf("Expected panic message about HTTPTimeout, got: %s", msg)
}
}
}()
WithHTTPTimeout(-1 * time.Second)
}
func TestWithHTTPTimeout_Zero(t *testing.T) {
// Zero should not panic (uses default)
defer func() {
if r := recover(); r != nil {
t.Errorf("Did not expect panic for HTTPTimeout=0, got: %v", r)
}
}()
cfg := config{}
opt := WithHTTPTimeout(0)
opt(&cfg)
if cfg.HTTPTimeout != 0 {
t.Errorf("HTTPTimeout = %v, want 0", cfg.HTTPTimeout)
}
}
func TestWithMaxBytes(t *testing.T) {
cfg := config{}
opt := WithMaxBytes(100 << 20) // 100MB
opt(&cfg)
if cfg.MaxBytes != 100<<20 {
t.Errorf("WithMaxBytes() MaxBytes = %v, want 100MB", cfg.MaxBytes)
}
}
func TestWithMaxBytes_Zero(t *testing.T) {
cfg := config{}
opt := WithMaxBytes(0) // unlimited
opt(&cfg)
if cfg.MaxBytes != 0 {
t.Errorf("WithMaxBytes(0) MaxBytes = %v, want 0", cfg.MaxBytes)
}
}
func TestWithMaxBytes_Negative(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for negative MaxBytes")
} else if msg, ok := r.(string); ok {
if msg != "imx: MaxBytes must be non-negative" {
t.Errorf("Expected panic message about MaxBytes, got: %s", msg)
}
}
}()
WithMaxBytes(-1)
}
func TestWithBufferSize(t *testing.T) {
cfg := config{}
opt := WithBufferSize(128 << 10) // 128KB
opt(&cfg)
if cfg.BufferSize != 128<<10 {
t.Errorf("WithBufferSize() BufferSize = %v, want 128KB", cfg.BufferSize)
}
}
func TestWithBufferSize_Zero(t *testing.T) {
cfg := config{}
opt := WithBufferSize(0) // uses default
opt(&cfg)
if cfg.BufferSize != 0 {
t.Errorf("WithBufferSize(0) BufferSize = %v, want 0", cfg.BufferSize)
}
}
func TestWithBufferSize_Negative(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for negative BufferSize")
} else if msg, ok := r.(string); ok {
if msg != "imx: BufferSize must be non-negative" {
t.Errorf("Expected panic message about BufferSize, got: %s", msg)
}
}
}()
WithBufferSize(-1)
}