Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
caddyfile: Export NewTestDispenser() (close #2930)
This allows modules to test their UnmarshalCaddyfile methods.
Matthew Holt committed
Apr 1, 2020 at 16:34 UTC
6fe04a30b102cc9aaa9d0df717c9fbb73f276139
2 files changed
+11
-9
caddyconfig/caddyfile/dispenser_test.go
+10
-8
@@ -27,7 +27,7 @@ func TestDispenser_Val_Next(t *testing.T) {
27
dir1 arg1
28
dir2 arg2 arg3
29
dir3`
30
- d := newTestDispenser(input)
30
+ d := NewTestDispenser(input)
31
32
if val := d.Val(); val != "" {
33
t.Fatalf("Val(): Should return empty string when no token loaded; got '%s'", val)
@@ -65,7 +65,7 @@ func TestDispenser_NextArg(t *testing.T) {
65
input := `dir1 arg1
66
dir2 arg2 arg3
67
dir3`
68
- d := newTestDispenser(input)
68
+ d := NewTestDispenser(input)
69
70
assertNext := func(shouldLoad bool, expectedVal string, expectedCursor int) {
71
if d.Next() != shouldLoad {
@@ -112,7 +112,7 @@ func TestDispenser_NextLine(t *testing.T) {
112
input := `host:port
113
dir1 arg1
114
dir2 arg2 arg3`
115
- d := newTestDispenser(input)
115
+ d := NewTestDispenser(input)
116
117
assertNextLine := func(shouldLoad bool, expectedVal string, expectedCursor int) {
118
if d.NextLine() != shouldLoad {
@@ -145,7 +145,7 @@ func TestDispenser_NextBlock(t *testing.T) {
145
}
146
foobar2 {
147
}`
148
- d := newTestDispenser(input)
148
+ d := NewTestDispenser(input)
149
150
assertNextBlock := func(shouldLoad bool, expectedCursor, expectedNesting int) {
151
if loaded := d.NextBlock(0); loaded != shouldLoad {
@@ -175,7 +175,7 @@ func TestDispenser_Args(t *testing.T) {
175
dir2 arg4 arg5
176
dir3 arg6 arg7
177
dir4`
178
- d := newTestDispenser(input)
178
+ d := NewTestDispenser(input)
179
180
d.Next() // dir1
181
@@ -242,7 +242,7 @@ func TestDispenser_RemainingArgs(t *testing.T) {
242
dir2 arg4 arg5
243
dir3 arg6 { arg7
244
dir4`
245
- d := newTestDispenser(input)
245
+ d := NewTestDispenser(input)
246
247
d.Next() // dir1
248
@@ -279,7 +279,7 @@ func TestDispenser_ArgErr_Err(t *testing.T) {
279
input := `dir1 {
280
}
281
dir2 arg1 arg2`
282
- d := newTestDispenser(input)
282
+ d := NewTestDispenser(input)
283
284
d.cursor = 1 // {
285
@@ -307,7 +307,9 @@ func TestDispenser_ArgErr_Err(t *testing.T) {
307
}
308
}
309
310
-func newTestDispenser(input string) *Dispenser {
310
+// NewTestDispenser parses input into tokens and creates a new
311
+// Disenser for test purposes only; any errors are fatal.
312
+func NewTestDispenser(input string) *Dispenser {
313
tokens, err := allTokens("Testfile", []byte(input))
314
if err != nil && err != io.EOF {
315
log.Fatalf("getting all tokens from input: %v", err)
caddyconfig/caddyfile/parse_test.go
+1
-1
@@ -670,5 +670,5 @@ func TestSnippetAcrossMultipleFiles(t *testing.T) {
670
}
671
672
func testParser(input string) parser {
673
- return parser{Dispenser: newTestDispenser(input)}
673
+ return parser{Dispenser: NewTestDispenser(input)}
674
}