mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
Enable debug globally if enabled in any server config (#4007)
* Enable debug globally if enabled in any server config It was currently enabled only if the plugin debug was enabled in the last server config of the Corefile. Signed-off-by: Olivier Lemasle <o.lemasle@gmail.com> * Add test and update debug's README Signed-off-by: Olivier Lemasle <o.lemasle@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/log"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
@@ -48,6 +49,33 @@ func TestNewServer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebug(t *testing.T) {
|
||||
configNoDebug, configDebug := testConfig("dns", testPlugin{}), testConfig("dns", testPlugin{})
|
||||
configDebug.Debug = true
|
||||
|
||||
s1, err := NewServer("127.0.0.1:53", []*Config{configDebug, configNoDebug})
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error for NewServer, got %s", err)
|
||||
}
|
||||
if !s1.debug {
|
||||
t.Errorf("Expected debug mode enabled for server s1")
|
||||
}
|
||||
if !log.D.Value() {
|
||||
t.Errorf("Expected debug logging enabled")
|
||||
}
|
||||
|
||||
s2, err := NewServer("127.0.0.1:53", []*Config{configNoDebug})
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error for NewServer, got %s", err)
|
||||
}
|
||||
if s2.debug {
|
||||
t.Errorf("Expected debug mode disabled for server s2")
|
||||
}
|
||||
if log.D.Value() {
|
||||
t.Errorf("Expected debug logging disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCoreServeDNS(b *testing.B) {
|
||||
s, err := NewServer("127.0.0.1:53", []*Config{testConfig("dns", testPlugin{})})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user