mirror of https://github.com/0xERR0R/blocky.git
Adds a test to cover the last missing line in codecov for answer creation errors
This commit is contained in:
parent
b010d0c76d
commit
7743666862
|
@ -18,6 +18,7 @@ import (
|
|||
// CustomDNSResolver resolves passed domain name to ip address defined in domain-IP map
|
||||
type CustomDNSResolver struct {
|
||||
configurable[*config.CustomDNS]
|
||||
CreateAnswerFromQuestion func(question dns.Question, ip net.IP, ttl uint32) (dns.RR, error)
|
||||
NextResolver
|
||||
typed
|
||||
|
||||
|
@ -51,8 +52,9 @@ func NewCustomDNSResolver(cfg config.CustomDNS) *CustomDNSResolver {
|
|||
}
|
||||
|
||||
return &CustomDNSResolver{
|
||||
configurable: withConfig(&cfg),
|
||||
typed: withType("custom_dns"),
|
||||
configurable: withConfig(&cfg),
|
||||
CreateAnswerFromQuestion: util.CreateAnswerFromQuestion,
|
||||
typed: withType("custom_dns"),
|
||||
|
||||
mapping: m,
|
||||
reverseAddresses: reverse,
|
||||
|
@ -186,7 +188,7 @@ func (r *CustomDNSResolver) processIP(ip net.IP, question dns.Question) (result
|
|||
result = make([]dns.RR, 0)
|
||||
|
||||
if isSupportedType(ip, question) {
|
||||
rr, err := util.CreateAnswerFromQuestion(question, ip, r.cfg.CustomTTL.SecondsU32())
|
||||
rr, err := r.CreateAnswerFromQuestion(question, ip, r.cfg.CustomTTL.SecondsU32())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -91,7 +91,20 @@ var _ = Describe("CustomDNSResolver", func() {
|
|||
Expect(err.Error()).Should(ContainSubstring("context canceled"))
|
||||
})
|
||||
})
|
||||
When("Creating the IP response returns an error ", func() {
|
||||
It("should return the error", func() {
|
||||
createAnswerMock := func(_ dns.Question, _ net.IP, _ uint32) (dns.RR, error) {
|
||||
return nil, fmt.Errorf("create answer error")
|
||||
}
|
||||
|
||||
sut.CreateAnswerFromQuestion = createAnswerMock
|
||||
|
||||
_, err := sut.Resolve(ctx, newRequest("custom.domain.", A))
|
||||
|
||||
Expect(err).Should(HaveOccurred())
|
||||
Expect(err.Error()).Should(ContainSubstring("create answer error"))
|
||||
})
|
||||
})
|
||||
When("The forward request returns an error ", func() {
|
||||
It("should return the error if the error occurs when checking ipv4 forward addresses", func() {
|
||||
err := fmt.Errorf("forward error")
|
||||
|
|
Loading…
Reference in New Issue