all: imp code
This commit is contained in:
parent
1ad99ee3cb
commit
0b4311ac26
|
@ -236,7 +236,7 @@ func (p *DefaultAddrProc) Process(ctx context.Context, ip netip.Addr) {
|
||||||
// to be used as a goroutine. Once clientIPs is closed, process exits.
|
// to be used as a goroutine. Once clientIPs is closed, process exits.
|
||||||
func (p *DefaultAddrProc) process(ctx context.Context, catchPanics bool) {
|
func (p *DefaultAddrProc) process(ctx context.Context, catchPanics bool) {
|
||||||
if catchPanics {
|
if catchPanics {
|
||||||
slogutil.RecoverAndLog(ctx, p.logger)
|
defer slogutil.RecoverAndLog(ctx, p.logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.logger.InfoContext(ctx, "processing addresses")
|
p.logger.InfoContext(ctx, "processing addresses")
|
||||||
|
|
|
@ -21,6 +21,17 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// testStorage is a helper function that returns initialized storage.
|
||||||
|
func testStorage(tb testing.TB) (s *client.Storage) {
|
||||||
|
ctx := testutil.ContextWithTimeout(tb, testTimeout)
|
||||||
|
s, err := client.NewStorage(ctx, &client.StorageConfig{
|
||||||
|
Logger: slogutil.NewDiscardLogger(),
|
||||||
|
})
|
||||||
|
require.NoError(tb, err)
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// testHostsContainer is a mock implementation of the [client.HostsContainer]
|
// testHostsContainer is a mock implementation of the [client.HostsContainer]
|
||||||
// interface.
|
// interface.
|
||||||
type testHostsContainer struct {
|
type testHostsContainer struct {
|
||||||
|
@ -571,11 +582,7 @@ func TestStorage_Add(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
||||||
s, err := client.NewStorage(ctx, &client.StorageConfig{
|
s := testStorage(t)
|
||||||
Logger: slogutil.NewDiscardLogger(),
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
tags := s.AllowedTags()
|
tags := s.AllowedTags()
|
||||||
require.NotZero(t, len(tags))
|
require.NotZero(t, len(tags))
|
||||||
require.True(t, slices.IsSorted(tags))
|
require.True(t, slices.IsSorted(tags))
|
||||||
|
@ -586,7 +593,7 @@ func TestStorage_Add(t *testing.T) {
|
||||||
_, ok = slices.BinarySearch(tags, notAllowedTag)
|
_, ok = slices.BinarySearch(tags, notAllowedTag)
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
|
|
||||||
err = s.Add(ctx, existingClient)
|
err := s.Add(ctx, existingClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -706,12 +713,8 @@ func TestStorage_RemoveByName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
||||||
s, err := client.NewStorage(ctx, &client.StorageConfig{
|
s := testStorage(t)
|
||||||
Logger: slogutil.NewDiscardLogger(),
|
err := s.Add(ctx, existingClient)
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = s.Add(ctx, existingClient)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -735,11 +738,7 @@ func TestStorage_RemoveByName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("duplicate_remove", func(t *testing.T) {
|
t.Run("duplicate_remove", func(t *testing.T) {
|
||||||
s, err = client.NewStorage(ctx, &client.StorageConfig{
|
s = testStorage(t)
|
||||||
Logger: slogutil.NewDiscardLogger(),
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = s.Add(ctx, existingClient)
|
err = s.Add(ctx, existingClient)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -115,10 +115,10 @@ func Main(clientBuildFS fs.FS) {
|
||||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
|
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
ctx := context.Background()
|
||||||
for {
|
for {
|
||||||
sig := <-signals
|
sig := <-signals
|
||||||
log.Info("Received signal %q", sig)
|
log.Info("Received signal %q", sig)
|
||||||
ctx := context.Background()
|
|
||||||
switch sig {
|
switch sig {
|
||||||
case syscall.SIGHUP:
|
case syscall.SIGHUP:
|
||||||
Context.clients.storage.ReloadARP(ctx)
|
Context.clients.storage.ReloadARP(ctx)
|
||||||
|
|
Loading…
Reference in New Issue