Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caddyfile: Make NewTestDispenser accessible for plugin authors #3439

Merged
merged 1 commit into from
May 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
caddyfile: Make NewTestDispenser accessible for plugin authors
francislavoie committed May 23, 2020

Verified

This commit was signed with the committer’s verified signature.
sagikazarmark Márk Sági-Kazár
commit ba900841e595cb544501f11b0b1a0aca417be1c7
12 changes: 12 additions & 0 deletions caddyconfig/caddyfile/dispenser.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ package caddyfile
import (
"errors"
"fmt"
"io"
"log"
"strings"
)

@@ -37,6 +39,16 @@ func NewDispenser(tokens []Token) *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)
}
return NewDispenser(tokens)
}

// Next loads the next token. Returns true if a token
// was loaded; false otherwise. If false, all tokens
// have been consumed.
12 changes: 0 additions & 12 deletions caddyconfig/caddyfile/dispenser_test.go
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@
package caddyfile

import (
"io"
"log"
"reflect"
"strings"
"testing"
@@ -306,13 +304,3 @@ func TestDispenser_ArgErr_Err(t *testing.T) {
t.Errorf("Expected error message with custom message in it ('foobar'); got '%v'", err)
}
}

// 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)
}
return NewDispenser(tokens)
}