agdtest

package
v0.0.0-...-b6e3791 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package agdtest contains simple mocks for common interfaces and other test utilities.

Index

Constants

View Source
const FilteredResponseTTL = FilteredResponseTTLSec * time.Second

FilteredResponseTTL is the common filtering response TTL for tests. It is also used by NewConstructor.

View Source
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

func ContextWithTimeout(tb testing.TB, timeout time.Duration) (ctx context.Context)

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 NewCloner

func NewCloner() (c *dnsmsg.Cloner)

NewCloner returns a standard dnsmsg.Cloner for tests.

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.

func (*BillStatRecorder) Record

func (r *BillStatRecorder) Record(
	ctx context.Context,
	id agd.DeviceID,
	ctry geoip.Country,
	asn geoip.ASN,
	start time.Time,
	proto agd.Protocol,
)

Record implements the billstat.Recorder interface for *BillStatRecorder.

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

func (b *BillStatUploader) Upload(ctx context.Context, records billstat.Records) (err error)

Upload implements the billstat.Uploader interface for *BillStatUploader.

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.

func (*DNSCheck) Check

func (db *DNSCheck) Check(
	ctx context.Context,
	req *dns.Msg,
	ri *agd.RequestInfo,
) (resp *dns.Msg, err error)

Check implements the dnscheck.Interface interface for *DNSCheck.

type DNSDB

type DNSDB struct {
	OnRecord func(ctx context.Context, resp *dns.Msg, ri *agd.RequestInfo)
}

DNSDB is a dnsdb.Interface for tests.

func (*DNSDB) Record

func (db *DNSDB) Record(ctx context.Context, resp *dns.Msg, ri *agd.RequestInfo)

Record implements the dnsdb.Interface interface for *DNSDB.

type ErrorCollector

type ErrorCollector struct {
	OnCollect func(ctx context.Context, err error)
}

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) Data

func (g *GeoIP) Data(host string, ip netip.Addr) (l *geoip.Location, err error)

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 {
	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.

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) ProfileByLinkedIP

func (db *ProfileDB) ProfileByLinkedIP(
	ctx context.Context,
	ip netip.Addr,
) (p *agd.Profile, d *agd.Device, err error)

ProfileByLinkedIP 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 QueryLog

type QueryLog struct {
	OnWrite func(ctx context.Context, e *querylog.Entry) (err error)
}

QueryLog is a querylog.Interface for tests.

func (*QueryLog) Write

func (ql *QueryLog) Write(ctx context.Context, e *querylog.Entry) (err error)

Write implements the querylog.Interface interface for *QueryLog.

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

func (l *RateLimit) CountResponses(ctx context.Context, req *dns.Msg, ip netip.Addr)

CountResponses implements the ratelimit.Interface interface for *RateLimit.

func (*RateLimit) IsRateLimited

func (l *RateLimit) IsRateLimited(
	ctx context.Context,
	req *dns.Msg,
	ip netip.Addr,
) (drop, allowlisted bool, err error)

IsRateLimited implements the ratelimit.Interface interface for *RateLimit.

type Refresher

type Refresher struct {
	OnRefresh func(ctx context.Context) (err error)
}

Refresher is an agdservice.Refresher for tests.

func (*Refresher) Refresh

func (r *Refresher) Refresh(ctx context.Context) (err error)

Refresh implements the agdservice.Refresher interface for *Refresher.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL