-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_statics_test.go
147 lines (142 loc) · 2.39 KB
/
api_statics_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"net/http"
"testing"
"time"
)
func Test_headerSize(t *testing.T) {
type args struct {
headers http.Header
}
tests := []struct {
name string
args args
wantResult int64
}{
{
name: "with header",
args: args{
http.Header{
"header": []string{"application/json"},
},
},
wantResult: 28,
},
{
name: "without header",
args: args{
http.Header{},
},
wantResult: 2,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotResult := headerSize(tt.args.headers); gotResult != tt.wantResult {
t.Errorf("headerSize() = %v, want %v", gotResult, tt.wantResult)
}
})
}
}
func Test_findMaxRequestTime(t *testing.T) {
tm := func(d string) time.Duration {
dr, _ := time.ParseDuration(d)
return dr
}
type args struct {
t1 time.Duration
t2 time.Duration
}
tests := []struct {
name string
args args
want time.Duration
}{
{
name: "test1",
args: args{
t1: tm("10s"),
t2: tm("5s"),
},
want: tm("10s"),
},
{
name: "test2",
args: args{
t1: tm("5s"),
t2: tm("10s"),
},
want: tm("10s"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findMaxRequestTime(tt.args.t1, tt.args.t2); got != tt.want {
t.Errorf("findMaxRequestTime() = %v, want %v", got, tt.want)
}
})
}
}
func Test_findMinRequestTime(t *testing.T) {
tm := func(d string) time.Duration {
dr, _ := time.ParseDuration(d)
return dr
}
type args struct {
t1 time.Duration
t2 time.Duration
}
tests := []struct {
name string
args args
want time.Duration
}{
{
name: "test1",
args: args{
t1: tm("10s"),
t2: tm("5s"),
},
want: tm("5s"),
},
{
name: "test2",
args: args{
t1: tm("5s"),
t2: tm("10s"),
},
want: tm("5s"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := findMinRequestTime(tt.args.t1, tt.args.t2); got != tt.want {
t.Errorf("findMinRequestTime() = %v, want %v", got, tt.want)
}
})
}
}
func TestAPIConfig_stop(t *testing.T) {
type fields struct {
interrupt int32
}
tests := []struct {
name string
fields fields
}{
{
name: "test1",
fields: fields{
interrupt: 1,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := &APIConfig{
interrupt: tt.fields.interrupt,
}
conf.stop()
})
}
}