From 460c0c8a42933df6416085dfcd9a4caef49c68f1 Mon Sep 17 00:00:00 2001 From: Abiola Ibrahim Date: Sat, 20 Jun 2015 14:59:33 +0100 Subject: [PATCH] setup: export functions and variables for external packages. --- config/directives.go | 4 ++-- config/setup/basicauth_test.go | 8 ++++---- .../{controller_test.go => controllertest.go} | 12 ++++++------ config/setup/ext_test.go | 8 ++++---- config/setup/git_test.go | 8 ++++---- config/setup/gzip_test.go | 8 ++++---- config/setup/headers_test.go | 8 ++++---- config/setup/internal_test.go | 8 ++++---- config/setup/log_test.go | 8 ++++---- config/setup/rewrite_test.go | 10 +++++----- config/setup/tls_test.go | 16 ++++++++-------- 11 files changed, 49 insertions(+), 49 deletions(-) rename config/setup/{controller_test.go => controllertest.go} (62%) diff --git a/config/directives.go b/config/directives.go index 9db5df44..56c70db5 100644 --- a/config/directives.go +++ b/config/directives.go @@ -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) diff --git a/config/setup/basicauth_test.go b/config/setup/basicauth_test.go index 0f9d044e..f5cb8067 100644 --- a/config/setup/basicauth_test.go +++ b/config/setup/basicauth_test.go @@ -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 { diff --git a/config/setup/controller_test.go b/config/setup/controllertest.go similarity index 62% rename from config/setup/controller_test.go rename to config/setup/controllertest.go index 225d031e..dcb2ca82 100644 --- a/config/setup/controller_test.go +++ b/config/setup/controllertest.go @@ -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) } diff --git a/config/setup/ext_test.go b/config/setup/ext_test.go index 2054b56a..24e3cf94 100644 --- a/config/setup/ext_test.go +++ b/config/setup/ext_test.go @@ -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 { diff --git a/config/setup/git_test.go b/config/setup/git_test.go index 226f8305..7207e0d9 100644 --- a/config/setup/git_test.go +++ b/config/setup/git_test.go @@ -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) diff --git a/config/setup/gzip_test.go b/config/setup/gzip_test.go index b228dbcc..30ef7422 100644 --- a/config/setup/gzip_test.go +++ b/config/setup/gzip_test.go @@ -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) diff --git a/config/setup/headers_test.go b/config/setup/headers_test.go index 81c758ae..412e7664 100644 --- a/config/setup/headers_test.go +++ b/config/setup/headers_test.go @@ -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 { diff --git a/config/setup/internal_test.go b/config/setup/internal_test.go index f6ab4386..f4d0ed8b 100644 --- a/config/setup/internal_test.go +++ b/config/setup/internal_test.go @@ -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 { diff --git a/config/setup/log_test.go b/config/setup/log_test.go index 29ebf41d..6f8e1cce 100644 --- a/config/setup/log_test.go +++ b/config/setup/log_test.go @@ -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 { diff --git a/config/setup/rewrite_test.go b/config/setup/rewrite_test.go index 5747dee3..6ce8d97e 100644 --- a/config/setup/rewrite_test.go +++ b/config/setup/rewrite_test.go @@ -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 { diff --git a/config/setup/tls_test.go b/config/setup/tls_test.go index 04ac6cce..fe1ce655 100644 --- a/config/setup/tls_test.go +++ b/config/setup/tls_test.go @@ -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")