2021-09-09 21:24:27 +02:00
|
|
|
package mocks
|
|
|
|
|
2022-05-14 19:38:46 +02:00
|
|
|
import (
|
2022-05-16 10:46:53 +02:00
|
|
|
"net"
|
|
|
|
|
2022-05-14 19:38:46 +02:00
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
|
|
)
|
2021-09-27 23:09:41 +02:00
|
|
|
|
2021-09-28 10:47:59 +02:00
|
|
|
// DNSDecoder allows mocking dnsx.DNSDecoder.
|
|
|
|
type DNSDecoder struct {
|
2022-05-14 19:38:46 +02:00
|
|
|
MockDecodeLookupHost func(qtype uint16, reply []byte, queryID uint16) ([]string, error)
|
2022-05-16 10:46:53 +02:00
|
|
|
MockDecodeHTTPS func(reply []byte, queryID uint16) (*model.HTTPSSvc, error)
|
|
|
|
MockDecodeNS func(reply []byte, queryID uint16) ([]*net.NS, error)
|
|
|
|
MockDecodeReply func(reply []byte) (*dns.Msg, error)
|
2021-09-27 23:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeLookupHost calls MockDecodeLookupHost.
|
2022-05-14 19:38:46 +02:00
|
|
|
func (e *DNSDecoder) DecodeLookupHost(qtype uint16, reply []byte, queryID uint16) ([]string, error) {
|
|
|
|
return e.MockDecodeLookupHost(qtype, reply, queryID)
|
2021-09-09 21:24:27 +02:00
|
|
|
}
|
|
|
|
|
2021-09-27 23:09:41 +02:00
|
|
|
// DecodeHTTPS calls MockDecodeHTTPS.
|
2022-05-14 19:38:46 +02:00
|
|
|
func (e *DNSDecoder) DecodeHTTPS(reply []byte, queryID uint16) (*model.HTTPSSvc, error) {
|
|
|
|
return e.MockDecodeHTTPS(reply, queryID)
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:46:53 +02:00
|
|
|
// DecodeNS calls MockDecodeNS.
|
|
|
|
func (e *DNSDecoder) DecodeNS(reply []byte, queryID uint16) ([]*net.NS, error) {
|
|
|
|
return e.MockDecodeNS(reply, queryID)
|
|
|
|
}
|
|
|
|
|
2022-05-14 19:38:46 +02:00
|
|
|
// DecodeReply calls MockDecodeReply.
|
|
|
|
func (e *DNSDecoder) DecodeReply(reply []byte) (*dns.Msg, error) {
|
|
|
|
return e.MockDecodeReply(reply)
|
2021-09-09 21:24:27 +02:00
|
|
|
}
|