Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
caddy
Commits
ebae65b6
Commit
ebae65b6
authored
Jun 20, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #157 from abiosoft/master
setup: export functions and variables for external packages.
parents
528d1b03
460c0c8a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
49 additions
and
49 deletions
+49
-49
config/directives.go
config/directives.go
+2
-2
config/setup/basicauth_test.go
config/setup/basicauth_test.go
+4
-4
config/setup/controllertest.go
config/setup/controllertest.go
+6
-6
config/setup/ext_test.go
config/setup/ext_test.go
+4
-4
config/setup/git_test.go
config/setup/git_test.go
+4
-4
config/setup/gzip_test.go
config/setup/gzip_test.go
+4
-4
config/setup/headers_test.go
config/setup/headers_test.go
+4
-4
config/setup/internal_test.go
config/setup/internal_test.go
+4
-4
config/setup/log_test.go
config/setup/log_test.go
+4
-4
config/setup/rewrite_test.go
config/setup/rewrite_test.go
+5
-5
config/setup/tls_test.go
config/setup/tls_test.go
+8
-8
No files found.
config/directives.go
View file @
ebae65b6
...
...
@@ -71,10 +71,10 @@ var directiveOrder = []directive{
// directive ties together a directive name with its setup function.
type
directive
struct
{
name
string
setup
s
etupFunc
setup
S
etupFunc
}
// 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
s
etupFunc
func
(
c
*
setup
.
Controller
)
(
middleware
.
Middleware
,
error
)
type
S
etupFunc
func
(
c
*
setup
.
Controller
)
(
middleware
.
Middleware
,
error
)
config/setup/basicauth_test.go
View file @
ebae65b6
...
...
@@ -8,7 +8,7 @@ import (
)
func
TestBasicAuth
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`basicauth user pwd`
)
c
:=
N
ewTestController
(
`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
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
myHandler
,
ok
:=
handler
.
(
basicauth
.
BasicAuth
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type BasicAuth, got: %#v"
,
handler
)
}
if
!
sameNext
(
myHandler
.
Next
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
input
)
c
:=
N
ewTestController
(
test
.
input
)
actual
,
err
:=
basicAuthParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
...
...
config/setup/controller
_
test.go
→
config/setup/controllertest.go
View file @
ebae65b6
...
...
@@ -10,23 +10,23 @@ import (
"github.com/mholt/caddy/server"
)
//
n
ewTestController creates a new *Controller for
//
N
ewTestController creates a new *Controller for
// the input specified, with a filename of "Testfile"
func
n
ewTestController
(
input
string
)
*
Controller
{
func
N
ewTestController
(
input
string
)
*
Controller
{
return
&
Controller
{
Config
:
&
server
.
Config
{},
Dispenser
:
parse
.
NewDispenser
(
"Testfile"
,
strings
.
NewReader
(
input
)),
}
}
//
e
mptyNext is a no-op function that can be passed into
//
E
mptyNext 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
e
mptyNext
=
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
var
E
mptyNext
=
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
return
0
,
nil
})
//
s
ameNext does a pointer comparison between next1 and next2.
func
s
ameNext
(
next1
,
next2
middleware
.
Handler
)
bool
{
//
S
ameNext does a pointer comparison between next1 and next2.
func
S
ameNext
(
next1
,
next2
middleware
.
Handler
)
bool
{
return
fmt
.
Sprintf
(
"%p"
,
next1
)
==
fmt
.
Sprintf
(
"%p"
,
next2
)
}
config/setup/ext_test.go
View file @
ebae65b6
...
...
@@ -7,7 +7,7 @@ import (
)
func
TestExt
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`ext .html .htm .php`
)
c
:=
N
ewTestController
(
`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
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
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
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
inputExts
)
c
:=
N
ewTestController
(
test
.
inputExts
)
actualExts
,
err
:=
extParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
...
...
config/setup/git_test.go
View file @
ebae65b6
...
...
@@ -22,7 +22,7 @@ func check(t *testing.T, err error) {
}
func
TestGit
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`git git@github.com:mholt/caddy.git`
)
c
:=
N
ewTestController
(
`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
:=
n
ewTestController
(
test
)
c1
:=
N
ewTestController
(
test
)
repo
,
err
:=
gitParse
(
c1
)
check
(
t
,
err
)
c2
:=
n
ewTestController
(
test
)
c2
:=
N
ewTestController
(
test
)
_
,
err
=
Git
(
c2
)
check
(
t
,
err
)
...
...
@@ -166,7 +166,7 @@ func TestGitParse(t *testing.T) {
}
for
i
,
test
:=
range
tests
{
c
:=
n
ewTestController
(
test
.
input
)
c
:=
N
ewTestController
(
test
.
input
)
repo
,
err
:=
gitParse
(
c
)
if
!
test
.
shouldErr
&&
err
!=
nil
{
t
.
Errorf
(
"Test %v should not error but found %v"
,
i
,
err
)
...
...
config/setup/gzip_test.go
View file @
ebae65b6
...
...
@@ -7,7 +7,7 @@ import (
)
func
TestGzip
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`gzip`
)
c
:=
N
ewTestController
(
`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
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
myHandler
,
ok
:=
handler
.
(
gzip
.
Gzip
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type Gzip, got: %#v"
,
handler
)
}
if
!
sameNext
(
myHandler
.
Next
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
input
)
c
:=
N
ewTestController
(
test
.
input
)
_
,
err
:=
gzipParse
(
c
)
if
test
.
shouldErr
&&
err
==
nil
{
t
.
Errorf
(
"Test %v: Expected error but found nil"
,
i
)
...
...
config/setup/headers_test.go
View file @
ebae65b6
...
...
@@ -8,7 +8,7 @@ import (
)
func
TestHeaders
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`header / Foo Bar`
)
c
:=
N
ewTestController
(
`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
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
myHandler
,
ok
:=
handler
.
(
headers
.
Headers
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type Headers, got: %#v"
,
handler
)
}
if
!
sameNext
(
myHandler
.
Next
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
input
)
c
:=
N
ewTestController
(
test
.
input
)
actual
,
err
:=
headersParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
...
...
config/setup/internal_test.go
View file @
ebae65b6
...
...
@@ -7,7 +7,7 @@ import (
)
func
TestInternal
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`internal /internal`
)
c
:=
N
ewTestController
(
`internal /internal`
)
mid
,
err
:=
Internal
(
c
)
...
...
@@ -19,7 +19,7 @@ func TestInternal(t *testing.T) {
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
handler
:=
mid
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
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
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
inputInternalPaths
)
c
:=
N
ewTestController
(
test
.
inputInternalPaths
)
actualInternalPaths
,
err
:=
internalParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
...
...
config/setup/log_test.go
View file @
ebae65b6
...
...
@@ -8,7 +8,7 @@ import (
func
TestLog
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`log`
)
c
:=
N
ewTestController
(
`log`
)
mid
,
err
:=
Log
(
c
)
...
...
@@ -20,7 +20,7 @@ func TestLog(t *testing.T) {
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
handler
:=
mid
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
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
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
inputLogRules
)
c
:=
N
ewTestController
(
test
.
inputLogRules
)
actualLogRules
,
err
:=
logParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
...
...
config/setup/rewrite_test.go
View file @
ebae65b6
...
...
@@ -10,7 +10,7 @@ import (
)
func
TestRewrite
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`rewrite /from /to`
)
c
:=
N
ewTestController
(
`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
(
e
mptyNext
)
handler
:=
mid
(
E
mptyNext
)
myHandler
,
ok
:=
handler
.
(
rewrite
.
Rewrite
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type Rewrite, got: %#v"
,
handler
)
}
if
!
sameNext
(
myHandler
.
Next
,
e
mptyNext
)
{
if
!
SameNext
(
myHandler
.
Next
,
E
mptyNext
)
{
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
:=
n
ewTestController
(
test
.
input
)
c
:=
N
ewTestController
(
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
:=
n
ewTestController
(
test
.
input
)
c
:=
N
ewTestController
(
test
.
input
)
actual
,
err
:=
rewriteParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
...
...
config/setup/tls_test.go
View file @
ebae65b6
...
...
@@ -6,7 +6,7 @@ import (
)
func
TestTLSParseBasic
(
t
*
testing
.
T
)
{
c
:=
n
ewTestController
(
`tls cert.pem key.pem`
)
c
:=
N
ewTestController
(
`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
:=
n
ewTestController
(
`tls`
)
c
:=
N
ewTestController
(
`tls`
)
_
,
err
:=
TLS
(
c
)
if
err
==
nil
{
t
.
Errorf
(
"Expected errors, but no error returned"
)
}
c
=
n
ewTestController
(
`tls cert.key`
)
c
=
N
ewTestController
(
`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
:=
n
ewTestController
(
params
)
c
:=
N
ewTestController
(
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
:=
n
ewTestController
(
params
)
c
:=
N
ewTestController
(
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
=
n
ewTestController
(
params
)
c
=
N
ewTestController
(
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
:=
n
ewTestController
(
params
)
c
:=
N
ewTestController
(
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
=
n
ewTestController
(
params
)
c
=
N
ewTestController
(
params
)
_
,
err
=
TLS
(
c
)
if
err
==
nil
{
t
.
Errorf
(
"Expected an error, but no error returned"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment