2021-09-09 21:24:27 +02:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
2021-09-28 10:47:59 +02:00
|
|
|
func TestDNSEncoder(t *testing.T) {
|
2021-09-09 21:24:27 +02:00
|
|
|
t.Run("Encode", func(t *testing.T) {
|
|
|
|
expected := errors.New("mocked error")
|
2021-09-28 10:47:59 +02:00
|
|
|
e := &DNSEncoder{
|
2022-05-14 19:38:46 +02:00
|
|
|
MockEncode: func(domain string, qtype uint16, padding bool) ([]byte, uint16, error) {
|
|
|
|
return nil, 0, expected
|
2021-09-09 21:24:27 +02:00
|
|
|
},
|
|
|
|
}
|
2022-05-14 19:38:46 +02:00
|
|
|
out, queryID, err := e.Encode("dns.google", dns.TypeA, true)
|
2021-09-09 21:24:27 +02:00
|
|
|
if !errors.Is(err, expected) {
|
|
|
|
t.Fatal("unexpected err", err)
|
|
|
|
}
|
|
|
|
if out != nil {
|
|
|
|
t.Fatal("unexpected out")
|
|
|
|
}
|
2022-05-14 19:38:46 +02:00
|
|
|
if queryID != 0 {
|
|
|
|
t.Fatal("unexpected queryID")
|
|
|
|
}
|
2021-09-09 21:24:27 +02:00
|
|
|
})
|
|
|
|
}
|