New test and test logger stettings

This commit is contained in:
Joona Hoikkala 2016-11-28 16:25:42 +02:00
parent cbf8337f2b
commit d33bda96fa
No known key found for this signature in database
GPG Key ID: C14AAE0F5ADCB854
4 changed files with 20 additions and 3 deletions

2
dns.go
View File

@ -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)
}

View File

@ -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) {

View File

@ -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)
}

View File

@ -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
}