feat(netxlite): implement LookupHTTPS (#514)
This new API call performs DNS lookups for HTTPS records. Part of https://github.com/ooni/probe/issues/1733 and diff has been extracted from https://github.com/ooni/probe-cli/pull/506.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package mocks
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/dnsx/model"
|
||||
)
|
||||
|
||||
// Resolver is a mockable Resolver.
|
||||
type Resolver struct {
|
||||
@@ -8,6 +12,7 @@ type Resolver struct {
|
||||
MockNetwork func() string
|
||||
MockAddress func() string
|
||||
MockCloseIdleConnections func()
|
||||
MockLookupHTTPS func(ctx context.Context, domain string) (*HTTPSSvc, error)
|
||||
}
|
||||
|
||||
// LookupHost calls MockLookupHost.
|
||||
@@ -29,3 +34,11 @@ func (r *Resolver) Network() string {
|
||||
func (r *Resolver) CloseIdleConnections() {
|
||||
r.MockCloseIdleConnections()
|
||||
}
|
||||
|
||||
// HTTPSSvc is an HTTPSSvc reply.
|
||||
type HTTPSSvc = model.HTTPSSvc
|
||||
|
||||
// LookupHTTPS calls MockLookupHTTPS.
|
||||
func (r *Resolver) LookupHTTPS(ctx context.Context, domain string) (*HTTPSSvc, error) {
|
||||
return r.MockLookupHTTPS(ctx, domain)
|
||||
}
|
||||
|
||||
@@ -58,4 +58,21 @@ func TestResolver(t *testing.T) {
|
||||
t.Fatal("not called")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("LookupHTTPS", func(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
r := &Resolver{
|
||||
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
|
||||
return nil, expected
|
||||
},
|
||||
}
|
||||
ctx := context.Background()
|
||||
https, err := r.LookupHTTPS(ctx, "dns.google")
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("unexpected error", err)
|
||||
}
|
||||
if https != nil {
|
||||
t.Fatal("expected nil addr")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user