diff --git a/dns.go b/dns.go index 6320af3..e5fe80e 100644 --- a/dns.go +++ b/dns.go @@ -87,7 +87,7 @@ func (r *Records) Parse(config general) { SOAstring := fmt.Sprintf("%s. SOA %s. %s. %s 28800 7200 604800 86400", strings.ToLower(config.Domain), strings.ToLower(config.Nsname), strings.ToLower(config.Nsadmin), serial) soarr, err := dns.NewRR(SOAstring) if err != nil { - log.WithFields(log.Fields{"error": err.Error(), "soa": SOAstring}).Warning("Error while adding SOA record") + log.WithFields(log.Fields{"error": err.Error(), "soa": SOAstring}).Error("Error while adding SOA record") } else { rrmap = appendRR(rrmap, soarr) } diff --git a/dns_test.go b/dns_test.go index 6c24c17..9a573ee 100644 --- a/dns_test.go +++ b/dns_test.go @@ -5,6 +5,7 @@ import ( "database/sql/driver" "errors" "fmt" + log "github.com/Sirupsen/logrus" "github.com/erikstmartin/go-testdb" "github.com/miekg/dns" "strings" @@ -106,7 +107,14 @@ func TestParse(t *testing.T) { Debug: false, } var testRR Records + loghook.Reset() testRR.Parse(testcfg) + if len(loghook.Entries) != 1 { + t.Errorf("Expected exactly one logged line, instead there was %d line(s)", len(loghook.Entries)) + } + if loghook.LastEntry().Level != log.ErrorLevel { + t.Error("Expected error level of ERROR from last message") + } } func TestResolveA(t *testing.T) { diff --git a/main_test.go b/main_test.go index 95987ea..d5288b3 100644 --- a/main_test.go +++ b/main_test.go @@ -3,10 +3,15 @@ package main import ( "flag" "fmt" + log "github.com/Sirupsen/logrus" + logrustest "github.com/Sirupsen/logrus/hooks/test" + "io/ioutil" "os" "testing" ) +var loghook = new(logrustest.Hook) + var ( postgres = flag.Bool("postgres", false, "run integration tests against PostgreSQL") ) @@ -19,6 +24,7 @@ var records = []string{ } func TestMain(m *testing.M) { + setupTestLogger() setupConfig() RR.Parse(DNSConf.General) flag.Parse() @@ -73,3 +79,8 @@ func setupConfig() { DNSConf = dnscfg } + +func setupTestLogger() { + log.SetOutput(ioutil.Discard) + log.AddHook(loghook) +} diff --git a/util.go b/util.go index 74d8964..67999cf 100644 --- a/util.go +++ b/util.go @@ -2,7 +2,6 @@ package main import ( "crypto/rand" - "fmt" "github.com/BurntSushi/toml" log "github.com/Sirupsen/logrus" "github.com/miekg/dns" @@ -44,7 +43,6 @@ func sanitizeDomainQuestion(d string) string { if firstDot > 0 { dom = dom[0:firstDot] } - fmt.Printf("%s\n", dom) return dom }