From 2d1ce165a5a11452809150cf558e00526069dfb3 Mon Sep 17 00:00:00 2001 From: YASH JAIN <76126720+osho-20@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:48:56 +0530 Subject: [PATCH] Issue-6671: Fixed the order of plugins. (#6729) * Issue-6671: Fixed the order of plugins. Signed-off-by: osho-20 * Issue-6671: corrected test cases. Signed-off-by: osho-20 * Issue-6671: fixed CoreDNSServerPorts Signed-off-by: osho-20 * Issue-6671: removed unnecessary change. Signed-off-by: osho-20 * Issue-6671: added extra check for error. Signed-off-by: osho-20 --------- Signed-off-by: osho-20 --- core/dnsserver/register.go | 7 +++++-- core/dnsserver/register_test.go | 2 +- core/dnsserver/server_test.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/dnsserver/register.go b/core/dnsserver/register.go index ae001b9f2..01cf00d7a 100644 --- a/core/dnsserver/register.go +++ b/core/dnsserver/register.go @@ -263,8 +263,11 @@ func (c *Config) Handlers() []plugin.Handler { return nil } hs := make([]plugin.Handler, 0, len(c.registry)) - for k := range c.registry { - hs = append(hs, c.registry[k]) + for _, k := range Directives { + registry := c.Handler(k) + if registry != nil { + hs = append(hs, registry) + } } return hs } diff --git a/core/dnsserver/register_test.go b/core/dnsserver/register_test.go index 4d3ce11e2..9a4c7263f 100644 --- a/core/dnsserver/register_test.go +++ b/core/dnsserver/register_test.go @@ -10,7 +10,7 @@ func TestHandler(t *testing.T) { 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 { + if h := c.Handler("local"); h != tp { t.Errorf("Expected testPlugin from Handler, got %T", h) } if h := c.Handler("nothing"); h != nil { diff --git a/core/dnsserver/server_test.go b/core/dnsserver/server_test.go index 9b9b0a35b..9c0652a86 100644 --- a/core/dnsserver/server_test.go +++ b/core/dnsserver/server_test.go @@ -17,7 +17,7 @@ func (tp testPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns. return 0, nil } -func (tp testPlugin) Name() string { return "testplugin" } +func (tp testPlugin) Name() string { return "local" } func testConfig(transport string, p plugin.Handler) *Config { c := &Config{