Skip to content

Commit

Permalink
all: imp tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Aug 15, 2022
1 parent 0d9d029 commit 95dc28d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions internal/aghalg/aghalg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

// Coalesce returns the first non-zero value. It is named after the function
// COALESCE in SQL except. If values or all it's elements are empty, it returns
// a zero value.
// COALESCE in SQL. If values or all its elements are empty, it returns a zero
// value.
func Coalesce[T comparable](values ...T) (res T) {
var zero T
for _, v := range values {
Expand Down
17 changes: 10 additions & 7 deletions internal/aghos/filewalker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
"github.com/stretchr/testify/require"
)

type errFS struct {
fs.GlobFS
}
// errFS is an fs.FS implementation, method Open of which always returns
// errFSOpen.
type errFS struct{}

const errErrFSOpen errors.Error = "this error is always returned"
// errFSOpen is returned from errGlobFS.Open.
const errFSOpen errors.Error = "test open error"

func (efs *errFS) Open(name string) (fs.File, error) {
return nil, errErrFSOpen
// Open implements the fs.FS interface for *errGlobFS. fsys is always nil and
// err is always errFSOpen.
func (efs *errFS) Open(name string) (fsys fs.File, err error) {
return nil, errFSOpen
}

func TestWalkerFunc_CheckFile(t *testing.T) {
Expand All @@ -33,7 +36,7 @@ func TestWalkerFunc_CheckFile(t *testing.T) {

t.Run("invalid_argument", func(t *testing.T) {
_, ok, err := checkFile(&errFS{}, nil, "")
require.ErrorIs(t, err, errErrFSOpen)
require.ErrorIs(t, err, errFSOpen)

assert.False(t, ok)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/aghtest/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func RespondTo(t testing.TB, req *dns.Msg, cl, qt uint16, targ, answer string) (
},
}
default:
t.Fatalf("unsupported question type: %s", dns.Type(qt).String())
t.Fatalf("unsupported question type: %s", dns.Type(qt))
}

return resp
Expand Down
4 changes: 2 additions & 2 deletions internal/filtering/safebrowsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestSafeBrowsingCache(t *testing.T) {
c.hashToHost[hash] = "sub.host.com"
assert.Equal(t, -1, c.getCached())

// Match "sub.host.com" from cache, but another hash for "host.example" is
// not in the cache which means that we must get data from server for it.
// Match "sub.host.com" from cache. Another hash for "host.example" is not
// in the cache, so get data for it from the server.
c.hashToHost = make(map[[32]byte]string)
hash = sha256.Sum256([]byte("sub.host.com"))
c.hashToHost[hash] = "sub.host.com"
Expand Down
12 changes: 6 additions & 6 deletions internal/v1/dnssvc/dnssvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Config struct {
// server addresses.
BootstrapServers []string

// UpstreamServers are the upstream DNS servers to use.
// UpstreamServers are the upstream DNS server addresses to use.
UpstreamServers []string

// UpstreamTimeout is the timeout for upstream requests.
Expand Down Expand Up @@ -71,7 +71,7 @@ func New(c *Config) (svc *Service, err error) {
if len(c.Upstreams) > 0 {
upstreams = c.Upstreams
} else {
upstreams, err = AddressesToUpstreams(
upstreams, err = addressesToUpstreams(
c.UpstreamServers,
c.BootstrapServers,
c.UpstreamTimeout,
Expand Down Expand Up @@ -99,10 +99,10 @@ func New(c *Config) (svc *Service, err error) {
return svc, nil
}

// AddressesToUpstreams is a wrapper around [upstream.AddressToUpstream]. It
// addressesToUpstreams is a wrapper around [upstream.AddressToUpstream]. It
// accepts a slice of addresses and other upstream parameters, and returns a
// slice of upstreams.
func AddressesToUpstreams(
func addressesToUpstreams(
upsStrs []string,
bootstraps []string,
timeout time.Duration,
Expand Down Expand Up @@ -153,8 +153,8 @@ func udpAddrs(addrPorts []netip.AddrPort) (udpAddrs []*net.UDPAddr) {
var _ agh.Service = (*Service)(nil)

// Start implements the [agh.Service] interface for *Service. svc may be nil.
// After Start exits, all DNS servers have tried to start, possibly failing and
// writing error messages to the log.
// After Start exits, all DNS servers have tried to start, but there is no
// guarantee that they did. Errors from the servers are written to the log.
func (svc *Service) Start() (err error) {
if svc == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions internal/v1/dnssvc/dnssvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestService(t *testing.T) {
require.Len(t, gotConf.Addresses, 1)

addr := gotConf.Addresses[0]

t.Run("dns", func(t *testing.T) {
req := &dns.Msg{
MsgHdr: dns.MsgHdr{
Expand Down

0 comments on commit 95dc28d

Please sign in to comment.