| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 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)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2019-05-18 09:08:34 +01:00
										 |  |  | 	f.Reset()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-23 21:02:30 +01:00
										 |  |  | 	D.Set()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 	Debug("debug")
 | 
					
						
							|  |  |  | 	if x := f.String(); !strings.Contains(x, debug+"debug") {
 | 
					
						
							|  |  |  | 		t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2019-10-17 15:53:11 +01:00
										 |  |  | 	f.Reset()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	D.Clear()
 | 
					
						
							|  |  |  | 	Debug("debug")
 | 
					
						
							|  |  |  | 	if x := f.String(); x != "" {
 | 
					
						
							|  |  |  | 		t.Errorf("Expected no debug logs, got %s", x)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestDebugx(t *testing.T) {
 | 
					
						
							|  |  |  | 	var f bytes.Buffer
 | 
					
						
							|  |  |  | 	golog.SetOutput(&f)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-23 21:02:30 +01:00
										 |  |  | 	D.Set()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2019-05-18 09:08:34 +01:00
										 |  |  | 	f.Reset()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2019-05-18 09:08:34 +01:00
										 |  |  | 	f.Reset()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 	Warning(ts)
 | 
					
						
							|  |  |  | 	if x := f.String(); !strings.Contains(x, warning+ts) {
 | 
					
						
							|  |  |  | 		t.Errorf("Expected log to be %s, got %s", warning+ts, x)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2019-05-18 09:08:34 +01:00
										 |  |  | 	f.Reset()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 21:02:01 +01:00
										 |  |  | 	Error(ts)
 | 
					
						
							|  |  |  | 	if x := f.String(); !strings.Contains(x, err+ts) {
 | 
					
						
							|  |  |  | 		t.Errorf("Expected log to be %s, got %s", err+ts, x)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 |