mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-10 07:47:34 +07:00
New test and test logger stettings
This commit is contained in:
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)
|
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)
|
soarr, err := dns.NewRR(SOAstring)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
rrmap = appendRR(rrmap, soarr)
|
rrmap = appendRR(rrmap, soarr)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/erikstmartin/go-testdb"
|
"github.com/erikstmartin/go-testdb"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"strings"
|
"strings"
|
||||||
@ -106,7 +107,14 @@ func TestParse(t *testing.T) {
|
|||||||
Debug: false,
|
Debug: false,
|
||||||
}
|
}
|
||||||
var testRR Records
|
var testRR Records
|
||||||
|
loghook.Reset()
|
||||||
testRR.Parse(testcfg)
|
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) {
|
func TestResolveA(t *testing.T) {
|
||||||
|
11
main_test.go
11
main_test.go
@ -3,10 +3,15 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
logrustest "github.com/Sirupsen/logrus/hooks/test"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var loghook = new(logrustest.Hook)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
postgres = flag.Bool("postgres", false, "run integration tests against PostgreSQL")
|
postgres = flag.Bool("postgres", false, "run integration tests against PostgreSQL")
|
||||||
)
|
)
|
||||||
@ -19,6 +24,7 @@ var records = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
setupTestLogger()
|
||||||
setupConfig()
|
setupConfig()
|
||||||
RR.Parse(DNSConf.General)
|
RR.Parse(DNSConf.General)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -73,3 +79,8 @@ func setupConfig() {
|
|||||||
|
|
||||||
DNSConf = dnscfg
|
DNSConf = dnscfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupTestLogger() {
|
||||||
|
log.SetOutput(ioutil.Discard)
|
||||||
|
log.AddHook(loghook)
|
||||||
|
}
|
||||||
|
2
util.go
2
util.go
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
@ -44,7 +43,6 @@ func sanitizeDomainQuestion(d string) string {
|
|||||||
if firstDot > 0 {
|
if firstDot > 0 {
|
||||||
dom = dom[0:firstDot]
|
dom = dom[0:firstDot]
|
||||||
}
|
}
|
||||||
fmt.Printf("%s\n", dom)
|
|
||||||
return dom
|
return dom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user