diff options
author | Matthew Holt <[email protected]> | 2016-06-20 12:29:19 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2016-06-20 12:29:19 -0600 |
commit | 1fdc46e571cbacc628136fdf4a8ff3f1a9c08560 (patch) | |
tree | fafbaded6e3861e62e6730a0b767fd51fbda7212 | |
parent | a798e0c95191e07996c2a0d79087962d14e06464 (diff) | |
download | caddy-1fdc46e571cbacc628136fdf4a8ff3f1a9c08560.tar.gz caddy-1fdc46e571cbacc628136fdf4a8ff3f1a9c08560.zip |
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.
-rw-r--r-- | caddytls/setup_test.go | 20 | ||||
-rw-r--r-- | controller.go | 16 | ||||
-rw-r--r-- | startupshutdown/startupshutdown_test.go | 2 |
3 files changed, 21 insertions, 17 deletions
diff --git a/caddytls/setup_test.go b/caddytls/setup_test.go index c86af78bf..31c8ae1aa 100644 --- a/caddytls/setup_test.go +++ b/caddytls/setup_test.go @@ -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 { diff --git a/controller.go b/controller.go index c1fa627ae..0b8b7bc81 100644 --- a/controller.go +++ b/controller.go @@ -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() }, } diff --git a/startupshutdown/startupshutdown_test.go b/startupshutdown/startupshutdown_test.go index edbad3a53..9cc28437e 100644 --- a/startupshutdown/startupshutdown_test.go +++ b/startupshutdown/startupshutdown_test.go @@ -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) |