-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirective_test.go
70 lines (60 loc) · 1.58 KB
/
directive_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
// Copyright 2016 Sean Callahan. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package nginxconf
import (
"fmt"
"testing"
)
var testDirectives = []*Directive{
NewDirective("listen", "80"),
NewDirective("server_name", "example.com", "www.example.com"),
NewDirective("server", "127.0.0.1:3000", "weight=5"),
}
var testDirectivesText = []string{
"listen 80;",
"server_name example.com www.example.com;",
"server 127.0.0.1:3000 weight=5;",
}
var testBlocks = []*Directive{
NewDirective("server").AddChild(NewDirective("listen", "80")).AddChild(NewDirective("root", "/var/www/htdocs")),
NewDirective("server").AddChild(NewDirective("listen", "80")).AddChild(NewDirective("location", "/").AddChild(NewDirective("proxy_pass", "http://127.0.0.1:3000"))),
}
var testBlocksText = []string{
`server {
listen 80;
root /var/www/htdocs;
}`,
`server {
listen 80;
location / {
proxy_pass http://127.0.0.1:3000;
}
}`,
}
func TestNewDirective(t *testing.T) {
for i, d := range testDirectives {
if d.String() != testDirectivesText[i] {
t.Fail()
}
}
for i, b := range testBlocks {
if b.String() != testBlocksText[i] {
t.Fail()
}
}
}
func ExampleDirective() {
errorLog := NewDirective("error_log", "logs/error.log")
fmt.Println(errorLog)
// Output: error_log logs/error.log;
}
func ExampleDirective_block() {
server := NewDirective("server")
listen := NewDirective("listen", "443", "ssl")
server.AddChild(listen)
fmt.Println(server)
// Output: server {
// listen 443 ssl;
// }
}