2021-09-09 21:24:27 +02:00
|
|
|
package mocks
|
|
|
|
|
2022-05-25 17:03:58 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
|
|
)
|
2021-09-09 21:24:27 +02:00
|
|
|
|
2021-09-28 10:47:59 +02:00
|
|
|
// DNSTransport allows mocking dnsx.DNSTransport.
|
|
|
|
type DNSTransport struct {
|
2022-05-25 17:03:58 +02:00
|
|
|
MockRoundTrip func(ctx context.Context, query model.DNSQuery) (model.DNSResponse, error)
|
2021-09-09 21:24:27 +02:00
|
|
|
|
|
|
|
MockRequiresPadding func() bool
|
|
|
|
|
|
|
|
MockNetwork func() string
|
|
|
|
|
|
|
|
MockAddress func() string
|
|
|
|
|
|
|
|
MockCloseIdleConnections func()
|
|
|
|
}
|
|
|
|
|
2022-05-25 17:03:58 +02:00
|
|
|
var _ model.DNSTransport = &DNSTransport{}
|
|
|
|
|
2021-09-09 21:24:27 +02:00
|
|
|
// RoundTrip calls MockRoundTrip.
|
2022-05-25 17:03:58 +02:00
|
|
|
func (txp *DNSTransport) RoundTrip(ctx context.Context, query model.DNSQuery) (model.DNSResponse, error) {
|
2021-09-09 21:24:27 +02:00
|
|
|
return txp.MockRoundTrip(ctx, query)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequiresPadding calls MockRequiresPadding.
|
2021-09-28 10:47:59 +02:00
|
|
|
func (txp *DNSTransport) RequiresPadding() bool {
|
2021-09-09 21:24:27 +02:00
|
|
|
return txp.MockRequiresPadding()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Network calls MockNetwork.
|
2021-09-28 10:47:59 +02:00
|
|
|
func (txp *DNSTransport) Network() string {
|
2021-09-09 21:24:27 +02:00
|
|
|
return txp.MockNetwork()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Address calls MockAddress.
|
2021-09-28 10:47:59 +02:00
|
|
|
func (txp *DNSTransport) Address() string {
|
2021-09-09 21:24:27 +02:00
|
|
|
return txp.MockAddress()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CloseIdleConnections calls MockCloseIdleConnections.
|
2021-09-28 10:47:59 +02:00
|
|
|
func (txp *DNSTransport) CloseIdleConnections() {
|
2021-09-09 21:24:27 +02:00
|
|
|
txp.MockCloseIdleConnections()
|
|
|
|
}
|