mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
Instead of hardcoding plugin lists in autopath/health, use interfaces. (#1306)
Switched health and autopath plugin to allow any plugins to be used instead of a hardcoded list. I did not switch federation over since it wasn't obvious that anything other than kubernetes could be used with it. Fixes #1291
This commit is contained in:
committed by
Miek Gieben
parent
99e163c375
commit
a469a17cdf
@@ -167,6 +167,21 @@ func (c *Config) Handler(name string) plugin.Handler {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handlers returns a slice of plugins that have been registered. This can be used to
|
||||
// inspect and interact with registered plugins but cannot be used to remove or add plugins.
|
||||
// Note that this is order dependent and the order is defined in directives.go, i.e. if your plugin
|
||||
// comes before the plugin you are checking; it will not be there (yet).
|
||||
func (c *Config) Handlers() []plugin.Handler {
|
||||
if c.registry == nil {
|
||||
return nil
|
||||
}
|
||||
hs := make([]plugin.Handler, 0, len(c.registry))
|
||||
for k := range c.registry {
|
||||
hs = append(hs, c.registry[k])
|
||||
}
|
||||
return hs
|
||||
}
|
||||
|
||||
// groupSiteConfigsByListenAddr groups site configs by their listen
|
||||
// (bind) address, so sites that use the same listener can be served
|
||||
// on the same server instance. The return value maps the listen
|
||||
|
||||
31
core/dnsserver/register_test.go
Normal file
31
core/dnsserver/register_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package dnsserver
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHandler(t *testing.T) {
|
||||
tp := testPlugin{}
|
||||
c := testConfig("dns", tp)
|
||||
if _, err := NewServer("127.0.0.1:53", []*Config{c}); err != nil {
|
||||
t.Errorf("Expected no error for NewServer, got %s", err)
|
||||
}
|
||||
if h := c.Handler("testplugin"); h != tp {
|
||||
t.Errorf("Expected testPlugin from Handler, got %T", h)
|
||||
}
|
||||
if h := c.Handler("nothing"); h != nil {
|
||||
t.Errorf("Expected nil from Handler, got %T", h)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlers(t *testing.T) {
|
||||
tp := testPlugin{}
|
||||
c := testConfig("dns", tp)
|
||||
if _, err := NewServer("127.0.0.1:53", []*Config{c}); err != nil {
|
||||
t.Errorf("Expected no error for NewServer, got %s", err)
|
||||
}
|
||||
hs := c.Handlers()
|
||||
if len(hs) != 1 || hs[0] != tp {
|
||||
t.Errorf("Expected [testPlugin] from Handlers, got %v", hs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user