Documentation ¶
Overview ¶
Package agdtest contains simple mocks for common interfaces and other test utilities.
Index ¶
- Constants
- func ContextWithTimeout(tb testing.TB, timeout time.Duration) (ctx context.Context)
- func NewCloner() (c *dnsmsg.Cloner)
- func NewConstructor() (c *dnsmsg.Constructor)
- type AccessManager
- type BillStatRecorder
- type BillStatUploader
- type DNSCheck
- type DNSDB
- type ErrorCollector
- type Filter
- type FilterStorage
- type GeoIP
- type HashMatcher
- type ListenConfig
- type ProfileDB
- func (db *ProfileDB) ProfileByDedicatedIP(ctx context.Context, ip netip.Addr) (p *agd.Profile, d *agd.Device, err error)
- func (db *ProfileDB) ProfileByDeviceID(ctx context.Context, id agd.DeviceID) (p *agd.Profile, d *agd.Device, err error)
- func (db *ProfileDB) ProfileByLinkedIP(ctx context.Context, ip netip.Addr) (p *agd.Profile, d *agd.Device, err error)
- type ProfileStorage
- type QueryLog
- type RateLimit
- type Refresher
- type Resolver
- type RuleStat
Constants ¶
const FilteredResponseTTL = FilteredResponseTTLSec * time.Second
FilteredResponseTTL is the common filtering response TTL for tests. It is also used by NewConstructor.
const FilteredResponseTTLSec = 10
FilteredResponseTTLSec is the common filtering response TTL for tests, as a number to simplify message creation.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTimeout ¶
ContextWithTimeout is a helper that creates a new context with timeout and registers ctx's cleanup with t.Cleanup.
TODO(a.garipov): Move to golibs.
func NewConstructor ¶
func NewConstructor() (c *dnsmsg.Constructor)
NewConstructor returns a standard dnsmsg.Constructor for tests.
Types ¶
type AccessManager ¶
type AccessManager struct { OnIsBlockedHost func(host string, qt uint16) (blocked bool) OnIsBlockedIP func(ip netip.Addr) (blocked bool) }
AccessManager is a access.Interface for tests.
func (*AccessManager) IsBlockedHost ¶
func (a *AccessManager) IsBlockedHost(host string, qt uint16) (blocked bool)
IsBlockedHost implements the access.Interface interface for *AccessManager.
func (*AccessManager) IsBlockedIP ¶
func (a *AccessManager) IsBlockedIP(ip netip.Addr) (blocked bool)
IsBlockedIP implements the access.Interface interface for *AccessManager.
type BillStatRecorder ¶
type BillStatRecorder struct { OnRecord func( ctx context.Context, id agd.DeviceID, ctry geoip.Country, asn geoip.ASN, start time.Time, proto agd.Protocol, ) }
BillStatRecorder is a billstat.Recorder for tests.
type BillStatUploader ¶
type BillStatUploader struct {
OnUpload func(ctx context.Context, records billstat.Records) (err error)
}
BillStatUploader is a billstat.Uploader for tests.
type DNSCheck ¶
type DNSCheck struct {
OnCheck func(ctx context.Context, req *dns.Msg, ri *agd.RequestInfo) (reqp *dns.Msg, err error)
}
DNSCheck is a dnscheck.Interface for tests.
type ErrorCollector ¶
ErrorCollector is an errcoll.Interface for tests.
TODO(a.garipov): Actually test the error collection where this is used.
func (*ErrorCollector) Collect ¶
func (c *ErrorCollector) Collect(ctx context.Context, err error)
Collect implements the errcoll.Interface interface for *ErrorCollector.
type Filter ¶
type Filter struct { OnFilterRequest func( ctx context.Context, req *dns.Msg, ri *agd.RequestInfo, ) (r filter.Result, err error) OnFilterResponse func( ctx context.Context, resp *dns.Msg, ri *agd.RequestInfo, ) (r filter.Result, err error) }
Filter is a filter.Interface for tests.
func (*Filter) FilterRequest ¶
func (f *Filter) FilterRequest( ctx context.Context, req *dns.Msg, ri *agd.RequestInfo, ) (r filter.Result, err error)
FilterRequest implements the filter.Interface interface for *Filter.
func (*Filter) FilterResponse ¶
func (f *Filter) FilterResponse( ctx context.Context, resp *dns.Msg, ri *agd.RequestInfo, ) (r filter.Result, err error)
FilterResponse implements the filter.Interface interface for *Filter.
type FilterStorage ¶
type FilterStorage struct { OnFilterFromContext func(ctx context.Context, ri *agd.RequestInfo) (f filter.Interface) OnHasListID func(id agd.FilterListID) (ok bool) }
FilterStorage is a filter.Storage for tests.
func (*FilterStorage) FilterFromContext ¶
func (s *FilterStorage) FilterFromContext( ctx context.Context, ri *agd.RequestInfo, ) (f filter.Interface)
FilterFromContext implements the filter.Storage interface for *FilterStorage.
func (*FilterStorage) HasListID ¶
func (s *FilterStorage) HasListID(id agd.FilterListID) (ok bool)
HasListID implements the filter.Storage interface for *FilterStorage.
type GeoIP ¶
type GeoIP struct { OnSubnetByLocation func(l *geoip.Location, fam netutil.AddrFamily) (n netip.Prefix, err error) OnData func(host string, ip netip.Addr) (l *geoip.Location, err error) }
GeoIP is a geoip.Interface for tests.
func (*GeoIP) SubnetByLocation ¶
func (g *GeoIP) SubnetByLocation(l *geoip.Location, fam netutil.AddrFamily, ) (n netip.Prefix, err error)
SubnetByLocation implements the geoip.Interface interface for *GeoIP.
type HashMatcher ¶
type HashMatcher struct { OnMatchByPrefix func( ctx context.Context, host string, ) (hashes []string, matched bool, err error) }
HashMatcher is a filter.HashMatcher for tests.
func (*HashMatcher) MatchByPrefix ¶
func (m *HashMatcher) MatchByPrefix( ctx context.Context, host string, ) (hashes []string, matched bool, err error)
MatchByPrefix implements the filter.HashMatcher interface for *HashMatcher.
type ListenConfig ¶
type ListenConfig struct { OnListen func(ctx context.Context, network, address string) (l net.Listener, err error) OnListenPacket func( ctx context.Context, network string, address string, ) (conn net.PacketConn, err error) }
ListenConfig is a netext.ListenConfig for tests.
func (*ListenConfig) Listen ¶
func (c *ListenConfig) Listen( ctx context.Context, network string, address string, ) (l net.Listener, err error)
Listen implements the netext.ListenConfig interface for *ListenConfig.
func (*ListenConfig) ListenPacket ¶
func (c *ListenConfig) ListenPacket( ctx context.Context, network string, address string, ) (conn net.PacketConn, err error)
ListenPacket implements the netext.ListenConfig interface for *ListenConfig.
type ProfileDB ¶
type ProfileDB struct { OnProfileByDeviceID func( ctx context.Context, id agd.DeviceID, ) (p *agd.Profile, d *agd.Device, err error) OnProfileByDedicatedIP func( ctx context.Context, ip netip.Addr, ) (p *agd.Profile, d *agd.Device, err error) OnProfileByLinkedIP func( ctx context.Context, ip netip.Addr, ) (p *agd.Profile, d *agd.Device, err error) }
ProfileDB is a profiledb.Interface for tests.
func (*ProfileDB) ProfileByDedicatedIP ¶
func (db *ProfileDB) ProfileByDedicatedIP( ctx context.Context, ip netip.Addr, ) (p *agd.Profile, d *agd.Device, err error)
ProfileByDedicatedIP implements the profiledb.Interface interface for *ProfileDB.
type ProfileStorage ¶
type ProfileStorage struct { OnProfiles func( ctx context.Context, req *profiledb.StorageRequest, ) (resp *profiledb.StorageResponse, err error) }
ProfileStorage is a profiledb.Storage for tests.
func (*ProfileStorage) Profiles ¶
func (s *ProfileStorage) Profiles( ctx context.Context, req *profiledb.StorageRequest, ) (resp *profiledb.StorageResponse, err error)
Profiles implements the profiledb.Storage interface for *ProfileStorage.
type RateLimit ¶
type RateLimit struct { OnIsRateLimited func( ctx context.Context, req *dns.Msg, ip netip.Addr, ) (drop, allowlisted bool, err error) OnCountResponses func(ctx context.Context, resp *dns.Msg, ip netip.Addr) }
RateLimit is a ratelimit.Interface for tests.
func (*RateLimit) CountResponses ¶
CountResponses implements the ratelimit.Interface interface for *RateLimit.
type Refresher ¶
Refresher is an agdservice.Refresher for tests.
type Resolver ¶
type Resolver struct { OnLookupNetIP func( ctx context.Context, fam netutil.AddrFamily, host string, ) (ips []netip.Addr, err error) }
Resolver is an agdnet.Resolver for tests.
func (*Resolver) LookupNetIP ¶
func (r *Resolver) LookupNetIP( ctx context.Context, fam netutil.AddrFamily, host string, ) (ips []netip.Addr, err error)
LookupNetIP implements the agdnet.Resolver interface for *Resolver.
type RuleStat ¶
type RuleStat struct {
OnCollect func(ctx context.Context, id agd.FilterListID, text agd.FilterRuleText)
}
RuleStat is a rulestat.Interface for tests.
func (*RuleStat) Collect ¶
func (s *RuleStat) Collect(ctx context.Context, id agd.FilterListID, text agd.FilterRuleText)
Collect implements the rulestat.Interface interface for *RuleStat.