Files
routedns/resolver_test.go
Ali e51f51e1bc move from logrus to slog (#422)
* Migrate from logrus to slog

* fully removing logrus

* should be working now

* Update pipeline.go

Co-authored-by: Frank Olbricht <frank.olbricht@gmail.com>

* Update response-blocklist-name.go

Co-authored-by: Frank Olbricht <frank.olbricht@gmail.com>

* added null logger

* Update pipeline.go

---------

Co-authored-by: Frank Olbricht <frank.olbricht@gmail.com>
2025-01-13 08:43:30 +01:00

47 lines
918 B
Go

package rdns
import (
"errors"
"io"
"log/slog"
"github.com/miekg/dns"
)
func init() {
// Silence the logger while running tests
slog.SetDefault(slog.New(slog.NewTextHandler(io.Discard, nil)))
}
// TestResolver is a configurable resolver used for testing. It counts the
// number of queries, can be set to fail, and the resolve function can be
// defined externally.
type TestResolver struct {
ResolveFunc func(*dns.Msg, ClientInfo) (*dns.Msg, error)
hitCount int
shouldFail bool
}
func (r *TestResolver) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
r.hitCount++
if r.shouldFail {
return nil, errors.New("failed")
}
if r.ResolveFunc != nil {
return r.ResolveFunc(q, ci)
}
return q, nil
}
func (r *TestResolver) String() string {
return "TestResolver()"
}
func (r *TestResolver) HitCount() int {
return r.hitCount
}
func (r *TestResolver) SetFail(f bool) {
r.shouldFail = f
}