Documentation
¶
Overview ¶
Package agdtest contains simple mocks for common interfaces and other test utilities.
Index ¶
- Constants
- func NewCloner() (c *dnsmsg.Cloner)
- func NewConstructor(tb testing.TB) (c *dnsmsg.Constructor)
- func NewConstructorWithTTL(tb testing.TB, ttl time.Duration) (c *dnsmsg.Constructor)
- func NewSDEConfig(enabled bool) (c *dnsmsg.StructuredDNSErrorsConfig)
- type AccessManager
- type Authenticator
- type BillStatRecorder
- type BillStatUploader
- type Clock
- type DNSCheck
- type DNSDB
- type DeviceFinder
- type ErrorCollector
- type Filter
- type FilterStorage
- type GeoIP
- type HashMatcher
- type ListenConfig
- type ProfileDB
- func (db *ProfileDB) CreateAutoDevice(ctx context.Context, id agd.ProfileID, humanID agd.HumanID, ...) (p *agd.Profile, d *agd.Device, err error)
- 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) ProfileByHumanID(ctx context.Context, id agd.ProfileID, humanID agd.HumanIDLower) (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
- func (s *ProfileStorage) CreateAutoDevice(ctx context.Context, req *profiledb.StorageCreateAutoDeviceRequest) (resp *profiledb.StorageCreateAutoDeviceResponse, err error)
- func (s *ProfileStorage) Profiles(ctx context.Context, req *profiledb.StorageProfilesRequest) (resp *profiledb.StorageProfilesResponse, err error)
- type PrometheusRegisterer
- type QueryLog
- type RateLimit
- type Refresher
- type RemoteKV
- 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.
const SDEText = `{` +
`"j":"Filtering",` +
`"o":"Test Org",` +
`"c":["mailto:support@dns.example"]` +
`}`
SDEText is a test Structured DNS Error text.
NOTE: Keep in sync with NewSDEConfig.
TODO(e.burkov): Add some helper when this message becomes configurable.
Variables ¶
This section is empty.
Functions ¶
func NewConstructor ¶
func NewConstructor(tb testing.TB) (c *dnsmsg.Constructor)
NewConstructor returns a standard *dnsmsg.Constructor for tests, using FilteredResponseTTL as the TTL for filtered responses. The returned constructor also has the Structured DNS Errors feature enabled.
func NewConstructorWithTTL ¶
NewConstructorWithTTL returns a standard *dnsmsg.Constructor for tests, using ttl as the TTL for filtered responses.
func NewSDEConfig ¶
func NewSDEConfig(enabled bool) (c *dnsmsg.StructuredDNSErrorsConfig)
NewSDEConfig returns a standard *dnsmsg.StructuredDNSErrorsConfig 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 Authenticator ¶
Authenticator is an agdpasswd.Authenticator for tests.
func (*Authenticator) Authenticate ¶
func (a *Authenticator) Authenticate(ctx context.Context, passwd []byte) (ok bool)
Authenticate implements the agdpasswd.Authenticator interface for *Authenticator.
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.
func (*BillStatUploader) Upload ¶
Upload implements the billstat.Uploader interface for *BillStatUploader.
type Clock ¶
Clock is a agdtime.Clock 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 DNSDB ¶
DNSDB is a dnsdb.Interface for tests.
func (*DNSDB) Record ¶
Record implements the dnsdb.Interface interface for *DNSDB.
type DeviceFinder ¶
type DeviceFinder struct { OnFind func( ctx context.Context, req *dns.Msg, raddr netip.AddrPort, laddr netip.AddrPort, ) (r agd.DeviceResult) }
DeviceFinder is an agd.DeviceFinder for tests.
func (*DeviceFinder) Find ¶
func (f *DeviceFinder) Find( ctx context.Context, req *dns.Msg, raddr netip.AddrPort, laddr netip.AddrPort, ) (r agd.DeviceResult)
Find implements the agd.DeviceFinder interface for *DeviceFinder.
type ErrorCollector ¶
ErrorCollector is an errcoll.Interface for tests.
TODO(a.garipov): Actually test the error collection where this is used.
func NewErrorCollector ¶
func NewErrorCollector() (c *ErrorCollector)
NewErrorCollector returns a new *ErrorCollector all methods of which panic.
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 *filter.Request) (r filter.Result, err error) OnFilterResponse func(ctx context.Context, resp *filter.Response) (r filter.Result, err error) }
Filter is a filter.Interface for tests.
type FilterStorage ¶
type FilterStorage struct { OnForConfig func(ctx context.Context, c filter.Config) (f filter.Interface) OnHasListID func(id filter.ID) (ok bool) }
FilterStorage is a filter.Storage for tests.
func (*FilterStorage) ForConfig ¶
ForConfig implements the filter.Storage interface for *FilterStorage.
func (*FilterStorage) HasListID ¶
func (s *FilterStorage) HasListID(id filter.ID) (ok bool)
HasListID implements the filter.Storage interface for *FilterStorage.
type GeoIP ¶
type GeoIP struct { OnData func(host string, ip netip.Addr) (l *geoip.Location, err error) OnSubnetByLocation func(l *geoip.Location, fam netutil.AddrFamily) (n netip.Prefix, err error) }
GeoIP is a geoip.Interface for tests.
func NewGeoIP ¶
func NewGeoIP() (c *GeoIP)
NewGeoIP returns a new *GeoIP all methods of which panic.
func (*GeoIP) Data ¶
Data implements the geoip.Interface interface for *GeoIP.
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 { OnCreateAutoDevice func( ctx context.Context, id agd.ProfileID, humanID agd.HumanID, devType agd.DeviceType, ) (p *agd.Profile, d *agd.Device, err error) OnProfileByDedicatedIP func( ctx context.Context, ip netip.Addr, ) (p *agd.Profile, d *agd.Device, err error) OnProfileByDeviceID func( ctx context.Context, id agd.DeviceID, ) (p *agd.Profile, d *agd.Device, err error) OnProfileByHumanID func( ctx context.Context, id agd.ProfileID, humanID agd.HumanIDLower, ) (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 NewProfileDB ¶
func NewProfileDB() (db *ProfileDB)
NewProfileDB returns a new *ProfileDB all methods of which panic.
func (*ProfileDB) CreateAutoDevice ¶
func (db *ProfileDB) CreateAutoDevice( ctx context.Context, id agd.ProfileID, humanID agd.HumanID, devType agd.DeviceType, ) (p *agd.Profile, d *agd.Device, err error)
CreateAutoDevice implements the profiledb.Interface interface for *ProfileDB.
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.
func (*ProfileDB) ProfileByDeviceID ¶
func (db *ProfileDB) ProfileByDeviceID( ctx context.Context, id agd.DeviceID, ) (p *agd.Profile, d *agd.Device, err error)
ProfileByDeviceID implements the profiledb.Interface interface for *ProfileDB.
func (*ProfileDB) ProfileByHumanID ¶
func (db *ProfileDB) ProfileByHumanID( ctx context.Context, id agd.ProfileID, humanID agd.HumanIDLower, ) (p *agd.Profile, d *agd.Device, err error)
ProfileByHumanID implements the profiledb.Interface interface for *ProfileDB.
type ProfileStorage ¶
type ProfileStorage struct { OnCreateAutoDevice func( ctx context.Context, req *profiledb.StorageCreateAutoDeviceRequest, ) (resp *profiledb.StorageCreateAutoDeviceResponse, err error) OnProfiles func( ctx context.Context, req *profiledb.StorageProfilesRequest, ) (resp *profiledb.StorageProfilesResponse, err error) }
ProfileStorage is a profiledb.Storage implementation for tests.
func (*ProfileStorage) CreateAutoDevice ¶
func (s *ProfileStorage) CreateAutoDevice( ctx context.Context, req *profiledb.StorageCreateAutoDeviceRequest, ) (resp *profiledb.StorageCreateAutoDeviceResponse, err error)
CreateAutoDevice implements the profiledb.Storage interface for *ProfileStorage.
func (*ProfileStorage) Profiles ¶
func (s *ProfileStorage) Profiles( ctx context.Context, req *profiledb.StorageProfilesRequest, ) (resp *profiledb.StorageProfilesResponse, err error)
Profiles implements the profiledb.Storage interface for *ProfileStorage.
type PrometheusRegisterer ¶
type PrometheusRegisterer struct { OnRegister func(prometheus.Collector) (err error) OnMustRegister func(...prometheus.Collector) OnUnregister func(prometheus.Collector) (ok bool) }
PrometheusRegisterer is a prometheus.Registerer implementation for tests.
func NewTestPrometheusRegisterer ¶
func NewTestPrometheusRegisterer() (r *PrometheusRegisterer)
NewTestPrometheusRegisterer returns a prometheus.Registerer implementation that does nothing and returns nil from prometheus.Registerer.Register and true from prometheus.Registerer.Unregister.
func (*PrometheusRegisterer) MustRegister ¶
func (r *PrometheusRegisterer) MustRegister(collectors ...prometheus.Collector)
MustRegister implements the prometheus.Registerer interface for *PrometheusRegisterer.
func (*PrometheusRegisterer) Register ¶
func (r *PrometheusRegisterer) Register(c prometheus.Collector) (err error)
Register implements the prometheus.Registerer interface for *PrometheusRegisterer.
func (*PrometheusRegisterer) Unregister ¶
func (r *PrometheusRegisterer) Unregister(c prometheus.Collector) (ok bool)
Unregister implements the prometheus.Registerer interface for *PrometheusRegisterer.
type QueryLog ¶
QueryLog is a querylog.Interface for tests.
type RateLimit ¶
type RateLimit struct { OnIsRateLimited func( ctx context.Context, req *dns.Msg, ip netip.Addr, ) (shouldDrop, isAllowlisted bool, err error) OnCountResponses func(ctx context.Context, resp *dns.Msg, ip netip.Addr) }
RateLimit is a ratelimit.Interface for tests.
func NewRateLimit ¶
func NewRateLimit() (c *RateLimit)
NewRateLimit returns a new *RateLimit all methods of which panic.
func (*RateLimit) CountResponses ¶
CountResponses implements the ratelimit.Interface interface for *RateLimit.
type Refresher ¶
Refresher is an agdservice.Refresher for tests.
type RemoteKV ¶
type RemoteKV struct { OnGet func(ctx context.Context, key string) (val []byte, ok bool, err error) OnSet func(ctx context.Context, key string, val []byte) (err error) }
RemoteKV is an remotekv.Interface implementation for tests.
func (*RemoteKV) Get ¶
Get implements the remotekv.Interface interface for *RemoteKV.
type RuleStat ¶
RuleStat is a rulestat.Interface for tests.