talos/internal/pkg/ctxutil/ctxutil_test.go
Dmitriy Matrenichev ebeef28525
feat: implement local caching dns server
This PR adds a new controller - `DNSServerController` that starts tcp and udp dns servers locally. Just like `EtcFileController` it monitors `ResolverStatusType` and updates the list of destinations from there.

Most of the caching logic is in our "lobotomized" "`CoreDNS` fork. We need this fork because default `CoreDNS` carries
full Caddy server and various other modules that we don't need in Talos. On our side we implement
random selection of the actual dns and request forwarding.

Closes #7693

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
2024-01-29 20:26:38 +03:00

34 lines
794 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package ctxutil_test
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/require"
"github.com/siderolabs/talos/internal/pkg/ctxutil"
)
func TestStartFn(t *testing.T) {
ctx := ctxutil.MonitorFn(context.Background(), func() error { return nil })
<-ctx.Done()
require.Equal(t, context.Canceled, ctx.Err())
require.Nil(t, ctxutil.Cause(ctx))
myErr := errors.New("my error")
ctx = ctxutil.MonitorFn(context.Background(), func() error { return myErr })
<-ctx.Done()
require.Equal(t, context.Canceled, ctx.Err())
require.Equal(t, myErr, ctxutil.Cause(ctx))
}