2021-09-09 21:24:27 +02:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-09-09 21:24:27 +02:00
|
|
|
)
|
|
|
|
|
2021-09-28 10:47:59 +02:00
|
|
|
func TestDNSDecoder(t *testing.T) {
|
2022-05-25 17:03:58 +02:00
|
|
|
t.Run("DecodeResponse", func(t *testing.T) {
|
2021-09-09 21:24:27 +02:00
|
|
|
expected := errors.New("mocked error")
|
2021-09-28 10:47:59 +02:00
|
|
|
e := &DNSDecoder{
|
2022-05-25 17:03:58 +02:00
|
|
|
MockDecodeResponse: func(reply []byte, query model.DNSQuery) (model.DNSResponse, error) {
|
2021-09-09 21:24:27 +02:00
|
|
|
return nil, expected
|
|
|
|
},
|
|
|
|
}
|
2022-05-25 17:03:58 +02:00
|
|
|
out, err := e.DecodeResponse(make([]byte, 17), &DNSQuery{})
|
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")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|