0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

setup: export functions and variables for external packages.

This commit is contained in:
Abiola Ibrahim 2015-06-20 14:59:33 +01:00
parent 528d1b03f1
commit 460c0c8a42
11 changed files with 49 additions and 49 deletions

View file

@ -71,10 +71,10 @@ var directiveOrder = []directive{
// directive ties together a directive name with its setup function.
type directive struct {
name string
setup setupFunc
setup SetupFunc
}
// A setup function takes a setup controller. Its return values may
// both be nil. If middleware is not nil, it will be chained into
// the HTTP handlers in the order specified in this package.
type setupFunc func(c *setup.Controller) (middleware.Middleware, error)
type SetupFunc func(c *setup.Controller) (middleware.Middleware, error)

View file

@ -8,7 +8,7 @@ import (
)
func TestBasicAuth(t *testing.T) {
c := newTestController(`basicauth user pwd`)
c := NewTestController(`basicauth user pwd`)
mid, err := BasicAuth(c)
if err != nil {
@ -18,13 +18,13 @@ func TestBasicAuth(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(basicauth.BasicAuth)
if !ok {
t.Fatalf("Expected handler to be type BasicAuth, got: %#v", handler)
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
}
@ -62,7 +62,7 @@ func TestBasicAuthParse(t *testing.T) {
}
for i, test := range tests {
c := newTestController(test.input)
c := NewTestController(test.input)
actual, err := basicAuthParse(c)
if err == nil && test.shouldErr {

View file

@ -10,23 +10,23 @@ import (
"github.com/mholt/caddy/server"
)
// newTestController creates a new *Controller for
// NewTestController creates a new *Controller for
// the input specified, with a filename of "Testfile"
func newTestController(input string) *Controller {
func NewTestController(input string) *Controller {
return &Controller{
Config: &server.Config{},
Dispenser: parse.NewDispenser("Testfile", strings.NewReader(input)),
}
}
// emptyNext is a no-op function that can be passed into
// EmptyNext is a no-op function that can be passed into
// middleware.Middleware functions so that the assignment
// to the Next field of the Handler can be tested.
var emptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
return 0, nil
})
// sameNext does a pointer comparison between next1 and next2.
func sameNext(next1, next2 middleware.Handler) bool {
// SameNext does a pointer comparison between next1 and next2.
func SameNext(next1, next2 middleware.Handler) bool {
return fmt.Sprintf("%p", next1) == fmt.Sprintf("%p", next2)
}

View file

@ -7,7 +7,7 @@ import (
)
func TestExt(t *testing.T) {
c := newTestController(`ext .html .htm .php`)
c := NewTestController(`ext .html .htm .php`)
mid, err := Ext(c)
@ -19,7 +19,7 @@ func TestExt(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(extensions.Ext)
if !ok {
@ -35,7 +35,7 @@ func TestExt(t *testing.T) {
if myHandler.Extensions[2] != ".php" {
t.Errorf("Expected .php in the list of Extensions")
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
@ -52,7 +52,7 @@ func TestExtParse(t *testing.T) {
{`ext .txt .php .xml`, false, []string{".txt", ".php", ".xml"}},
}
for i, test := range tests {
c := newTestController(test.inputExts)
c := NewTestController(test.inputExts)
actualExts, err := extParse(c)
if err == nil && test.shouldErr {

View file

@ -22,7 +22,7 @@ func check(t *testing.T, err error) {
}
func TestGit(t *testing.T) {
c := newTestController(`git git@github.com:mholt/caddy.git`)
c := NewTestController(`git git@github.com:mholt/caddy.git`)
mid, err := Git(c)
check(t, err)
@ -43,11 +43,11 @@ func TestIntervals(t *testing.T) {
for i, test := range tests {
git.SetLogger(gittest.NewLogger(gittest.Open("file")))
c1 := newTestController(test)
c1 := NewTestController(test)
repo, err := gitParse(c1)
check(t, err)
c2 := newTestController(test)
c2 := NewTestController(test)
_, err = Git(c2)
check(t, err)
@ -166,7 +166,7 @@ func TestGitParse(t *testing.T) {
}
for i, test := range tests {
c := newTestController(test.input)
c := NewTestController(test.input)
repo, err := gitParse(c)
if !test.shouldErr && err != nil {
t.Errorf("Test %v should not error but found %v", i, err)

View file

@ -7,7 +7,7 @@ import (
)
func TestGzip(t *testing.T) {
c := newTestController(`gzip`)
c := NewTestController(`gzip`)
mid, err := Gzip(c)
if err != nil {
@ -17,13 +17,13 @@ func TestGzip(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(gzip.Gzip)
if !ok {
t.Fatalf("Expected handler to be type Gzip, got: %#v", handler)
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
@ -82,7 +82,7 @@ func TestGzip(t *testing.T) {
`, false},
}
for i, test := range tests {
c := newTestController(test.input)
c := NewTestController(test.input)
_, err := gzipParse(c)
if test.shouldErr && err == nil {
t.Errorf("Test %v: Expected error but found nil", i)

View file

@ -8,7 +8,7 @@ import (
)
func TestHeaders(t *testing.T) {
c := newTestController(`header / Foo Bar`)
c := NewTestController(`header / Foo Bar`)
mid, err := Headers(c)
if err != nil {
@ -18,13 +18,13 @@ func TestHeaders(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(headers.Headers)
if !ok {
t.Fatalf("Expected handler to be type Headers, got: %#v", handler)
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
}
@ -51,7 +51,7 @@ func TestHeadersParse(t *testing.T) {
}
for i, test := range tests {
c := newTestController(test.input)
c := NewTestController(test.input)
actual, err := headersParse(c)
if err == nil && test.shouldErr {

View file

@ -7,7 +7,7 @@ import (
)
func TestInternal(t *testing.T) {
c := newTestController(`internal /internal`)
c := NewTestController(`internal /internal`)
mid, err := Internal(c)
@ -19,7 +19,7 @@ func TestInternal(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(inner.Internal)
if !ok {
@ -30,7 +30,7 @@ func TestInternal(t *testing.T) {
t.Errorf("Expected internal in the list of internal Paths")
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
@ -48,7 +48,7 @@ func TestInternalParse(t *testing.T) {
internal /internal2`, false, []string{"/internal1", "/internal2"}},
}
for i, test := range tests {
c := newTestController(test.inputInternalPaths)
c := NewTestController(test.inputInternalPaths)
actualInternalPaths, err := internalParse(c)
if err == nil && test.shouldErr {

View file

@ -8,7 +8,7 @@ import (
func TestLog(t *testing.T) {
c := newTestController(`log`)
c := NewTestController(`log`)
mid, err := Log(c)
@ -20,7 +20,7 @@ func TestLog(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(caddylog.Logger)
if !ok {
@ -36,7 +36,7 @@ func TestLog(t *testing.T) {
if myHandler.Rules[0].Format != caddylog.DefaultLogFormat {
t.Errorf("Expected %s as the default Log Format", caddylog.DefaultLogFormat)
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
@ -100,7 +100,7 @@ func TestLogParse(t *testing.T) {
}}},
}
for i, test := range tests {
c := newTestController(test.inputLogRules)
c := NewTestController(test.inputLogRules)
actualLogRules, err := logParse(c)
if err == nil && test.shouldErr {

View file

@ -10,7 +10,7 @@ import (
)
func TestRewrite(t *testing.T) {
c := newTestController(`rewrite /from /to`)
c := NewTestController(`rewrite /from /to`)
mid, err := Rewrite(c)
if err != nil {
@ -20,13 +20,13 @@ func TestRewrite(t *testing.T) {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(emptyNext)
handler := mid(EmptyNext)
myHandler, ok := handler.(rewrite.Rewrite)
if !ok {
t.Fatalf("Expected handler to be type Rewrite, got: %#v", handler)
}
if !sameNext(myHandler.Next, emptyNext) {
if !SameNext(myHandler.Next, EmptyNext) {
t.Error("'Next' field of handler was not set properly")
}
@ -57,7 +57,7 @@ func TestRewriteParse(t *testing.T) {
}
for i, test := range simpleTests {
c := newTestController(test.input)
c := NewTestController(test.input)
actual, err := rewriteParse(c)
if err == nil && test.shouldErr {
@ -140,7 +140,7 @@ func TestRewriteParse(t *testing.T) {
}
for i, test := range regexpTests {
c := newTestController(test.input)
c := NewTestController(test.input)
actual, err := rewriteParse(c)
if err == nil && test.shouldErr {

View file

@ -6,7 +6,7 @@ import (
)
func TestTLSParseBasic(t *testing.T) {
c := newTestController(`tls cert.pem key.pem`)
c := NewTestController(`tls cert.pem key.pem`)
_, err := TLS(c)
if err != nil {
@ -66,14 +66,14 @@ func TestTLSParseBasic(t *testing.T) {
}
func TestTLSParseIncompleteParams(t *testing.T) {
c := newTestController(`tls`)
c := NewTestController(`tls`)
_, err := TLS(c)
if err == nil {
t.Errorf("Expected errors, but no error returned")
}
c = newTestController(`tls cert.key`)
c = NewTestController(`tls cert.key`)
_, err = TLS(c)
if err == nil {
@ -86,7 +86,7 @@ func TestTLSParseWithOptionalParams(t *testing.T) {
protocols ssl3.0 tls1.2
ciphers RSA-3DES-EDE-CBC-SHA RSA-AES256-CBC-SHA ECDHE-RSA-AES128-GCM-SHA256
}`
c := newTestController(params)
c := NewTestController(params)
_, err := TLS(c)
if err != nil {
@ -111,7 +111,7 @@ func TestTLSParseWithWrongOptionalParams(t *testing.T) {
params := `tls cert.crt cert.key {
protocols ssl tls
}`
c := newTestController(params)
c := NewTestController(params)
_, err := TLS(c)
if err == nil {
t.Errorf("Expected errors, but no error returned")
@ -121,7 +121,7 @@ func TestTLSParseWithWrongOptionalParams(t *testing.T) {
params = `tls cert.crt cert.key {
ciphers not-valid-cipher
}`
c = newTestController(params)
c = NewTestController(params)
_, err = TLS(c)
if err == nil {
t.Errorf("Expected errors, but no error returned")
@ -132,7 +132,7 @@ func TestTLSParseWithClientAuth(t *testing.T) {
params := `tls cert.crt cert.key {
clients client_ca.crt client2_ca.crt
}`
c := newTestController(params)
c := NewTestController(params)
_, err := TLS(c)
if err != nil {
t.Errorf("Expected no errors, got: %v", err)
@ -152,7 +152,7 @@ func TestTLSParseWithClientAuth(t *testing.T) {
params = `tls cert.crt cert.key {
clients
}`
c = newTestController(params)
c = NewTestController(params)
_, err = TLS(c)
if err == nil {
t.Errorf("Expected an error, but no error returned")