forked from tufanbarisyildirim/gonginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_test.go
68 lines (66 loc) · 1.38 KB
/
http_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
package gonginx
import (
"strings"
"testing"
)
func TestHttp_ToString(t *testing.T) {
type fields struct {
Directive *Directive
}
tests := []struct {
name string
fields fields
args *Style
want string
}{
{
name: "empty http block",
fields: fields{
Directive: &Directive{
Block: &Block{
Directives: make([]IDirective, 0),
},
Name: "http",
},
},
args: NoIndentStyle,
want: "http {\n\n}",
},
{
name: "styled http block with some directives",
fields: fields{
Directive: &Directive{
Block: &Block{
Directives: []IDirective{
&Directive{
Name: "access_log",
Parameters: []string{"logs/access.log", "main"},
},
&Directive{
Name: "default_type",
Parameters: []string{"application/octet-stream"},
},
},
},
Name: "http",
},
},
args: NewStyle(),
want: `http {
access_log logs/access.log main;
default_type application/octet-stream;
}`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, err := NewHttp(tt.fields.Directive)
if err != nil {
t.Error("NewHttp(tt.fields.Directive) failed")
}
if got := DumpDirective(s, tt.args); got != tt.want {
t.Errorf("Http.ToString() = \"%v\", want \"%v\"", strings.ReplaceAll(got, " ", "."), strings.ReplaceAll(tt.want, " ", "."))
}
})
}
}