mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 18:23:13 -04:00 
			
		
		
		
	* pkg/log: fix data race on d Wrap d in a mutex to prevent data race. This makes is slower, but this is a debugging aid anyway. It's not used normally. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests compilation Signed-off-by: Miek Gieben <miek@miek.nl> * Fix test compile Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package log
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	golog "log"
 | |
| 	"strings"
 | |
| 	"testing"
 | |
| )
 | |
| 
 | |
| func TestDebug(t *testing.T) {
 | |
| 	var f bytes.Buffer
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	// D == false
 | |
| 	Debug("debug")
 | |
| 	if x := f.String(); x != "" {
 | |
| 		t.Errorf("Expected no debug logs, got %s", x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 
 | |
| 	D.Set()
 | |
| 	Debug("debug")
 | |
| 	if x := f.String(); !strings.Contains(x, debug+"debug") {
 | |
| 		t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestDebugx(t *testing.T) {
 | |
| 	var f bytes.Buffer
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	D.Set()
 | |
| 
 | |
| 	Debugf("%s", "debug")
 | |
| 	if x := f.String(); !strings.Contains(x, debug+"debug") {
 | |
| 		t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 
 | |
| 	Debug("debug")
 | |
| 	if x := f.String(); !strings.Contains(x, debug+"debug") {
 | |
| 		t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestLevels(t *testing.T) {
 | |
| 	var f bytes.Buffer
 | |
| 	const ts = "test"
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	Info(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, info+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", info+ts, x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 	Warning(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, warning+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", warning+ts, x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 	Error(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, err+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", err+ts, x)
 | |
| 	}
 | |
| }
 |