mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 13:44:37 +03:00
switch to slog.Logger for logging, for easier reuse of packages by external software
we don't want external software to include internal details like mlog. slog.Logger is/will be the standard. we still have mlog for its helper functions, and its handler that logs in concise logfmt used by mox. packages that are not meant for reuse still pass around mlog.Log for convenience. we use golang.org/x/exp/slog because we also support the previous Go toolchain version. with the next Go release, we'll switch to the builtin slog.
This commit is contained in:
@ -6,10 +6,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mjl-/mox/dns"
|
||||
"github.com/mjl-/mox/mlog"
|
||||
)
|
||||
|
||||
func TestDNSBL(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
log := mlog.New("dnsbl", nil)
|
||||
|
||||
resolver := dns.MockResolver{
|
||||
A: map[string][]string{
|
||||
@ -23,7 +25,7 @@ func TestDNSBL(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if status, expl, err := Lookup(ctx, resolver, dns.Domain{ASCII: "example.com"}, net.ParseIP("10.0.0.1")); err != nil {
|
||||
if status, expl, err := Lookup(ctx, log.Logger, resolver, dns.Domain{ASCII: "example.com"}, net.ParseIP("10.0.0.1")); err != nil {
|
||||
t.Fatalf("lookup: %v", err)
|
||||
} else if status != StatusFail {
|
||||
t.Fatalf("lookup, got status %v, expected fail", status)
|
||||
@ -31,7 +33,7 @@ func TestDNSBL(t *testing.T) {
|
||||
t.Fatalf("lookup, got explanation %q", expl)
|
||||
}
|
||||
|
||||
if status, expl, err := Lookup(ctx, resolver, dns.Domain{ASCII: "example.com"}, net.ParseIP("2001:db8:1:2:3:4:567:89ab")); err != nil {
|
||||
if status, expl, err := Lookup(ctx, log.Logger, resolver, dns.Domain{ASCII: "example.com"}, net.ParseIP("2001:db8:1:2:3:4:567:89ab")); err != nil {
|
||||
t.Fatalf("lookup: %v", err)
|
||||
} else if status != StatusFail {
|
||||
t.Fatalf("lookup, got status %v, expected fail", status)
|
||||
@ -39,17 +41,17 @@ func TestDNSBL(t *testing.T) {
|
||||
t.Fatalf("lookup, got explanation %q", expl)
|
||||
}
|
||||
|
||||
if status, _, err := Lookup(ctx, resolver, dns.Domain{ASCII: "example.com"}, net.ParseIP("10.0.0.2")); err != nil {
|
||||
if status, _, err := Lookup(ctx, log.Logger, resolver, dns.Domain{ASCII: "example.com"}, net.ParseIP("10.0.0.2")); err != nil {
|
||||
t.Fatalf("lookup: %v", err)
|
||||
} else if status != StatusPass {
|
||||
t.Fatalf("lookup, got status %v, expected pass", status)
|
||||
}
|
||||
|
||||
// ../rfc/5782:357
|
||||
if err := CheckHealth(ctx, resolver, dns.Domain{ASCII: "example.com"}); err != nil {
|
||||
if err := CheckHealth(ctx, log.Logger, resolver, dns.Domain{ASCII: "example.com"}); err != nil {
|
||||
t.Fatalf("dnsbl not healthy: %v", err)
|
||||
}
|
||||
if err := CheckHealth(ctx, resolver, dns.Domain{ASCII: "example.org"}); err == nil {
|
||||
if err := CheckHealth(ctx, log.Logger, resolver, dns.Domain{ASCII: "example.org"}); err == nil {
|
||||
t.Fatalf("bad dnsbl is healthy")
|
||||
}
|
||||
|
||||
@ -58,7 +60,7 @@ func TestDNSBL(t *testing.T) {
|
||||
"1.0.0.127.example.com.": {"127.0.0.2"}, // Should not be present in healthy dnsbl.
|
||||
},
|
||||
}
|
||||
if err := CheckHealth(ctx, unhealthyResolver, dns.Domain{ASCII: "example.com"}); err == nil {
|
||||
if err := CheckHealth(ctx, log.Logger, unhealthyResolver, dns.Domain{ASCII: "example.com"}); err == nil {
|
||||
t.Fatalf("bad dnsbl is healthy")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user