forked from tufanbarisyildirim/gonginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupstream_server_test.go
86 lines (82 loc) · 1.89 KB
/
upstream_server_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
package gonginx
import (
"reflect"
"testing"
)
func TestNewUpstreamServer(t *testing.T) {
t.Parallel()
type args struct {
directive *Directive
}
tests := []struct {
name string
args args
want *UpstreamServer
wantString string
}{
{
name: "new upstream server",
args: args{
directive: &Directive{
Name: "server",
Parameters: []string{"127.0.0.1:8080"},
},
},
want: &UpstreamServer{
Address: "127.0.0.1:8080",
Flags: make([]string, 0),
Parameters: make(map[string]string, 0),
},
wantString: "server 127.0.0.1:8080;",
},
{
name: "new upstream server with weight",
args: args{
directive: &Directive{
Name: "server",
Parameters: []string{"127.0.0.1:8080", "weight=5"},
},
},
want: &UpstreamServer{
Address: "127.0.0.1:8080",
Flags: make([]string, 0),
Parameters: map[string]string{
"weight": "5",
},
},
wantString: "server 127.0.0.1:8080 weight=5;",
},
{
name: "new upstream server with weight and a flag",
args: args{
directive: &Directive{
Name: "server",
Parameters: []string{"127.0.0.1:8080", "weight=5", "down"},
},
},
want: &UpstreamServer{
Address: "127.0.0.1:8080",
Flags: []string{"down"},
Parameters: map[string]string{
"weight": "5",
},
},
wantString: "server 127.0.0.1:8080 weight=5 down;",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := NewUpstreamServer(tt.args.directive)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewUpstreamServer() = %v, want %v", got, tt.want)
}
if got.GetBlock() != nil {
t.Error("Upstream server returns a block")
}
gotString := DumpDirective(got, NoIndentStyle)
if gotString != tt.wantString {
t.Errorf("NewUpstreamServer().ToString = %v, want %v", gotString, tt.wantString)
}
})
}
}