Commit 1fdc46e5 authored by Matthew Holt's avatar Matthew Holt

Fix tests after controller refactor

The search-and-replace was a little too aggressive and I accidentally
ran tests recursively in a subdirectory instead of repo's top folder.
parent a798e0c9
......@@ -34,7 +34,7 @@ func TestMain(m *testing.M) {
func TestSetupParseBasic(t *testing.T) {
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", `tls `+certFile+` `+keyFile+``)
c := caddy.NewTestController("", `tls `+certFile+` `+keyFile+``)
err := setupTLS(c)
if err != nil {
......@@ -92,7 +92,7 @@ func TestSetupParseBasic(t *testing.T) {
func TestSetupParseIncompleteParams(t *testing.T) {
// Using tls without args is an error because it's unnecessary.
c := caddy.NewTestController("http", `tls`)
c := caddy.NewTestController("", `tls`)
err := setupTLS(c)
if err == nil {
t.Error("Expected an error, but didn't get one")
......@@ -106,7 +106,7 @@ func TestSetupParseWithOptionalParams(t *testing.T) {
}`
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params)
c := caddy.NewTestController("", params)
err := setupTLS(c)
if err != nil {
......@@ -132,7 +132,7 @@ func TestSetupDefaultWithOptionalParams(t *testing.T) {
}`
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params)
c := caddy.NewTestController("", params)
err := setupTLS(c)
if err != nil {
......@@ -150,7 +150,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
}`
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params)
c := caddy.NewTestController("", params)
err := setupTLS(c)
if err == nil {
t.Errorf("Expected errors, but no error returned")
......@@ -162,7 +162,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
}`
cfg = new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c = caddy.NewTestController("http", params)
c = caddy.NewTestController("", params)
err = setupTLS(c)
if err == nil {
t.Errorf("Expected errors, but no error returned")
......@@ -174,7 +174,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
}`
cfg = new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c = caddy.NewTestController("http", params)
c = caddy.NewTestController("", params)
err = setupTLS(c)
if err == nil {
t.Errorf("Expected errors, but no error returned")
......@@ -188,7 +188,7 @@ func TestSetupParseWithClientAuth(t *testing.T) {
}`
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params)
c := caddy.NewTestController("", params)
err := setupTLS(c)
if err == nil {
t.Errorf("Expected an error, but no error returned")
......@@ -221,7 +221,7 @@ func TestSetupParseWithClientAuth(t *testing.T) {
} {
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", caseData.params)
c := caddy.NewTestController("", caseData.params)
err := setupTLS(c)
if caseData.expectedErr {
if err == nil {
......@@ -257,7 +257,7 @@ func TestSetupParseWithKeyType(t *testing.T) {
}`
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params)
c := caddy.NewTestController("", params)
err := setupTLS(c)
if err != nil {
......
......@@ -7,8 +7,10 @@ import (
)
// Controller is given to the setup function of directives which
// gives them access to be able to read tokens and do whatever
// they need to do.
// gives them access to be able to read tokens with which to
// configure themselves. It also stores state for the setup
// functions, can get the current context, and can be used to
// identify a particular server block using the Key field.
type Controller struct {
caddyfile.Dispenser
......@@ -80,12 +82,14 @@ func (c *Controller) Context() Context {
// The Config is bare, consisting only of a Root of cwd.
//
// Used primarily for testing but needs to be exported so
// add-ons can use this as a convenience. Does not initialize
// the server-block-related fields.
// add-ons can use this as a convenience.
func NewTestController(serverType, input string) *Controller {
stype, _ := getServerType(serverType)
var ctx Context
if stype, err := getServerType(serverType); err == nil {
ctx = stype.NewContext()
}
return &Controller{
instance: &Instance{serverType: serverType, context: stype.NewContext()},
instance: &Instance{serverType: serverType, context: ctx},
Dispenser: caddyfile.NewDispenser("Testfile", strings.NewReader(input)),
OncePerServerBlock: func(f func() error) error { return f() },
}
......
......@@ -46,7 +46,7 @@ func TestStartup(t *testing.T) {
}
for i, test := range tests {
c := caddy.NewTestController("http", test.input)
c := caddy.NewTestController("", test.input)
err := registerCallback(c, fakeRegister)
if err != nil {
t.Errorf("Expected no errors, got: %v", err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment