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) { ...@@ -34,7 +34,7 @@ func TestMain(m *testing.M) {
func TestSetupParseBasic(t *testing.T) { func TestSetupParseBasic(t *testing.T) {
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", `tls `+certFile+` `+keyFile+``) c := caddy.NewTestController("", `tls `+certFile+` `+keyFile+``)
err := setupTLS(c) err := setupTLS(c)
if err != nil { if err != nil {
...@@ -92,7 +92,7 @@ func TestSetupParseBasic(t *testing.T) { ...@@ -92,7 +92,7 @@ func TestSetupParseBasic(t *testing.T) {
func TestSetupParseIncompleteParams(t *testing.T) { func TestSetupParseIncompleteParams(t *testing.T) {
// Using tls without args is an error because it's unnecessary. // Using tls without args is an error because it's unnecessary.
c := caddy.NewTestController("http", `tls`) c := caddy.NewTestController("", `tls`)
err := setupTLS(c) err := setupTLS(c)
if err == nil { if err == nil {
t.Error("Expected an error, but didn't get one") t.Error("Expected an error, but didn't get one")
...@@ -106,7 +106,7 @@ func TestSetupParseWithOptionalParams(t *testing.T) { ...@@ -106,7 +106,7 @@ func TestSetupParseWithOptionalParams(t *testing.T) {
}` }`
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params) c := caddy.NewTestController("", params)
err := setupTLS(c) err := setupTLS(c)
if err != nil { if err != nil {
...@@ -132,7 +132,7 @@ func TestSetupDefaultWithOptionalParams(t *testing.T) { ...@@ -132,7 +132,7 @@ func TestSetupDefaultWithOptionalParams(t *testing.T) {
}` }`
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params) c := caddy.NewTestController("", params)
err := setupTLS(c) err := setupTLS(c)
if err != nil { if err != nil {
...@@ -150,7 +150,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) { ...@@ -150,7 +150,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
}` }`
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params) c := caddy.NewTestController("", params)
err := setupTLS(c) err := setupTLS(c)
if err == nil { if err == nil {
t.Errorf("Expected errors, but no error returned") t.Errorf("Expected errors, but no error returned")
...@@ -162,7 +162,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) { ...@@ -162,7 +162,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
}` }`
cfg = new(Config) cfg = new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c = caddy.NewTestController("http", params) c = caddy.NewTestController("", params)
err = setupTLS(c) err = setupTLS(c)
if err == nil { if err == nil {
t.Errorf("Expected errors, but no error returned") t.Errorf("Expected errors, but no error returned")
...@@ -174,7 +174,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) { ...@@ -174,7 +174,7 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
}` }`
cfg = new(Config) cfg = new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c = caddy.NewTestController("http", params) c = caddy.NewTestController("", params)
err = setupTLS(c) err = setupTLS(c)
if err == nil { if err == nil {
t.Errorf("Expected errors, but no error returned") t.Errorf("Expected errors, but no error returned")
...@@ -188,7 +188,7 @@ func TestSetupParseWithClientAuth(t *testing.T) { ...@@ -188,7 +188,7 @@ func TestSetupParseWithClientAuth(t *testing.T) {
}` }`
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params) c := caddy.NewTestController("", params)
err := setupTLS(c) err := setupTLS(c)
if err == nil { if err == nil {
t.Errorf("Expected an error, but no error returned") t.Errorf("Expected an error, but no error returned")
...@@ -221,7 +221,7 @@ func TestSetupParseWithClientAuth(t *testing.T) { ...@@ -221,7 +221,7 @@ func TestSetupParseWithClientAuth(t *testing.T) {
} { } {
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", caseData.params) c := caddy.NewTestController("", caseData.params)
err := setupTLS(c) err := setupTLS(c)
if caseData.expectedErr { if caseData.expectedErr {
if err == nil { if err == nil {
...@@ -257,7 +257,7 @@ func TestSetupParseWithKeyType(t *testing.T) { ...@@ -257,7 +257,7 @@ func TestSetupParseWithKeyType(t *testing.T) {
}` }`
cfg := new(Config) cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("http", params) c := caddy.NewTestController("", params)
err := setupTLS(c) err := setupTLS(c)
if err != nil { if err != nil {
......
...@@ -7,8 +7,10 @@ import ( ...@@ -7,8 +7,10 @@ import (
) )
// Controller is given to the setup function of directives which // Controller is given to the setup function of directives which
// gives them access to be able to read tokens and do whatever // gives them access to be able to read tokens with which to
// they need to do. // 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 { type Controller struct {
caddyfile.Dispenser caddyfile.Dispenser
...@@ -80,12 +82,14 @@ func (c *Controller) Context() Context { ...@@ -80,12 +82,14 @@ func (c *Controller) Context() Context {
// The Config is bare, consisting only of a Root of cwd. // The Config is bare, consisting only of a Root of cwd.
// //
// Used primarily for testing but needs to be exported so // Used primarily for testing but needs to be exported so
// add-ons can use this as a convenience. Does not initialize // add-ons can use this as a convenience.
// the server-block-related fields.
func NewTestController(serverType, input string) *Controller { func NewTestController(serverType, input string) *Controller {
stype, _ := getServerType(serverType) var ctx Context
if stype, err := getServerType(serverType); err == nil {
ctx = stype.NewContext()
}
return &Controller{ return &Controller{
instance: &Instance{serverType: serverType, context: stype.NewContext()}, instance: &Instance{serverType: serverType, context: ctx},
Dispenser: caddyfile.NewDispenser("Testfile", strings.NewReader(input)), Dispenser: caddyfile.NewDispenser("Testfile", strings.NewReader(input)),
OncePerServerBlock: func(f func() error) error { return f() }, OncePerServerBlock: func(f func() error) error { return f() },
} }
......
...@@ -46,7 +46,7 @@ func TestStartup(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestStartup(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
c := caddy.NewTestController("http", test.input) c := caddy.NewTestController("", test.input)
err := registerCallback(c, fakeRegister) err := registerCallback(c, fakeRegister)
if err != nil { if err != nil {
t.Errorf("Expected no errors, got: %v", err) 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