diff options
author | Matthew Holt <[email protected]> | 2020-04-01 16:34:54 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2020-04-01 16:34:54 -0600 |
commit | 6fe04a30b102cc9aaa9d0df717c9fbb73f276139 (patch) | |
tree | c7690ded325c45fe990ce81e7d0d82ed035bea14 | |
parent | 19b45546a7507b5a4f13125c701df71fd1718ef7 (diff) | |
download | caddy-6fe04a30b102cc9aaa9d0df717c9fbb73f276139.tar.gz caddy-6fe04a30b102cc9aaa9d0df717c9fbb73f276139.zip |
caddyfile: Export NewTestDispenser() (close #2930)
This allows modules to test their UnmarshalCaddyfile methods.
-rwxr-xr-x | caddyconfig/caddyfile/dispenser_test.go | 18 | ||||
-rwxr-xr-x | caddyconfig/caddyfile/parse_test.go | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/caddyconfig/caddyfile/dispenser_test.go b/caddyconfig/caddyfile/dispenser_test.go index 86413a647..4970f9d3b 100755 --- a/caddyconfig/caddyfile/dispenser_test.go +++ b/caddyconfig/caddyfile/dispenser_test.go @@ -27,7 +27,7 @@ func TestDispenser_Val_Next(t *testing.T) { dir1 arg1 dir2 arg2 arg3 dir3` - d := newTestDispenser(input) + d := NewTestDispenser(input) if val := d.Val(); val != "" { t.Fatalf("Val(): Should return empty string when no token loaded; got '%s'", val) @@ -65,7 +65,7 @@ func TestDispenser_NextArg(t *testing.T) { input := `dir1 arg1 dir2 arg2 arg3 dir3` - d := newTestDispenser(input) + d := NewTestDispenser(input) assertNext := func(shouldLoad bool, expectedVal string, expectedCursor int) { if d.Next() != shouldLoad { @@ -112,7 +112,7 @@ func TestDispenser_NextLine(t *testing.T) { input := `host:port dir1 arg1 dir2 arg2 arg3` - d := newTestDispenser(input) + d := NewTestDispenser(input) assertNextLine := func(shouldLoad bool, expectedVal string, expectedCursor int) { if d.NextLine() != shouldLoad { @@ -145,7 +145,7 @@ func TestDispenser_NextBlock(t *testing.T) { } foobar2 { }` - d := newTestDispenser(input) + d := NewTestDispenser(input) assertNextBlock := func(shouldLoad bool, expectedCursor, expectedNesting int) { if loaded := d.NextBlock(0); loaded != shouldLoad { @@ -175,7 +175,7 @@ func TestDispenser_Args(t *testing.T) { dir2 arg4 arg5 dir3 arg6 arg7 dir4` - d := newTestDispenser(input) + d := NewTestDispenser(input) d.Next() // dir1 @@ -242,7 +242,7 @@ func TestDispenser_RemainingArgs(t *testing.T) { dir2 arg4 arg5 dir3 arg6 { arg7 dir4` - d := newTestDispenser(input) + d := NewTestDispenser(input) d.Next() // dir1 @@ -279,7 +279,7 @@ func TestDispenser_ArgErr_Err(t *testing.T) { input := `dir1 { } dir2 arg1 arg2` - d := newTestDispenser(input) + d := NewTestDispenser(input) d.cursor = 1 // { @@ -307,7 +307,9 @@ func TestDispenser_ArgErr_Err(t *testing.T) { } } -func newTestDispenser(input string) *Dispenser { +// NewTestDispenser parses input into tokens and creates a new +// Disenser for test purposes only; any errors are fatal. +func NewTestDispenser(input string) *Dispenser { tokens, err := allTokens("Testfile", []byte(input)) if err != nil && err != io.EOF { log.Fatalf("getting all tokens from input: %v", err) diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go index e6d050179..902a8e7f9 100755 --- a/caddyconfig/caddyfile/parse_test.go +++ b/caddyconfig/caddyfile/parse_test.go @@ -670,5 +670,5 @@ func TestSnippetAcrossMultipleFiles(t *testing.T) { } func testParser(input string) parser { - return parser{Dispenser: newTestDispenser(input)} + return parser{Dispenser: NewTestDispenser(input)} } |