mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-02-21 20:18:12 +07:00
New test and test logger stettings
This commit is contained in:
parent
cbf8337f2b
commit
d33bda96fa
2
dns.go
2
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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
11
main_test.go
11
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)
|
||||
}
|
||||
|
2
util.go
2
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user