-
Notifications
You must be signed in to change notification settings - Fork 56
/
reverseproxy_test.go
80 lines (72 loc) · 1.81 KB
/
reverseproxy_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
// Copyright yeqown The yeqown Author. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package proxy
import (
"testing"
)
func BenchmarkNewReverseProxy(b *testing.B) {
proxy, _ := NewReverseProxyWith(WithAddress("localhost:8080"))
if proxy == nil {
b.Fatalf("could not get from pool, proxy is nil")
}
for i := 0; i < b.N; i++ {
if proxy.getClient() == nil {
b.Fatalf("could not get from pool, client is nil")
}
// fmt.Println(proxy.client.Addr)
}
}
func BenchmarkNewReverseProxyWithBla(b *testing.B) {
weigths := map[string]Weight{
"localhost:8080": 10,
"localhost:8081": 30,
"localhost:8082": 60,
}
proxy, _ := NewReverseProxyWith(WithBalancer(weigths))
if proxy == nil {
b.Fatalf("could not get from pool, proxy is nil")
}
for i := 0; i < b.N; i++ {
if proxy.getClient() == nil {
b.Fatalf("could not get from pool, client is nil")
}
}
}
func Test_NewReverseProxy(t *testing.T) {
proxy, _ := NewReverseProxyWith(WithAddress("https://www.baidu.com"))
if proxy == nil {
t.Error("failed create NewReverseProxyWith")
t.FailNow()
}
client := proxy.getClient()
if client == nil {
t.Error("failed getClient")
t.FailNow()
}
if client.Addr != "https://www.baidu.com" {
t.Error("wrong init hostclient addr")
t.FailNow()
}
}
func Test_NewReversePorxyWithBalancer(t *testing.T) {
weights := map[string]Weight{
"http://localhost:9090": 20,
"http://localhost:9091": 30,
"http://localhost:9092": 50,
}
proxy, _ := NewReverseProxyWith(WithBalancer(weights))
if proxy == nil {
t.Error("failed create NewReverseProxyWith")
t.FailNow()
}
client := proxy.getClient()
if client == nil {
t.Error("failed getClient")
t.FailNow()
}
if client.Addr == "" {
t.Error("wrong init hostclient addr")
t.FailNow()
}
}