Documentation
¶
Overview ¶
Package testutil provides utilities for testing with mindns.
Package testutil provides utilities for testing with mindns. It exposes an in-process test server for integration testing.
Index ¶
- func ParseToken(token string) (keyID, secret string, err error)
- type APIKey
- type AuthStore
- func (s *AuthStore) CreateAPIKey(ctx context.Context, key *APIKey) (*APIKey, string, error)
- func (s *AuthStore) DeleteAPIKey(ctx context.Context, id string) error
- func (s *AuthStore) GetAPIKey(ctx context.Context, id string) (*APIKey, error)
- func (s *AuthStore) ListAPIKeys(ctx context.Context) ([]*APIKey, error)
- func (s *AuthStore) RevokeAPIKey(ctx context.Context, id string) error
- type Config
- type TestServer
- func (s *TestServer) AuthClient(token string) (mindnspb.MindnsServiceClient, *grpc.ClientConn, error)
- func (s *TestServer) AuthStore() *AuthStore
- func (s *TestServer) Client() (mindnspb.MindnsServiceClient, *grpc.ClientConn, error)
- func (s *TestServer) CreateZone(ctx context.Context, name string) error
- func (s *TestServer) DNSAddr() string
- func (s *TestServer) GRPCAddr() string
- func (s *TestServer) Manager() *zone.Manager
- func (s *TestServer) Start() error
- func (s *TestServer) StartAndWait(ctx context.Context) error
- func (s *TestServer) StartBackground()
- func (s *TestServer) Stop(ctx context.Context) error
- func (s *TestServer) Store() *store.Store
- func (s *TestServer) WaitReady(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseToken ¶ added in v0.8.0
ParseToken extracts the key ID and secret from a token string. Tokens have the format "keyid.secret".
Types ¶
type APIKey ¶ added in v0.8.0
type APIKey struct {
ID string
Scopes []string
Zones []string
Description string
CreatedAt time.Time
ExpiresAt *time.Time
LastUsedAt *time.Time
Revoked bool
}
APIKey represents an API key for authentication. This is a wrapper around the internal auth.APIKey type.
type AuthStore ¶ added in v0.8.0
type AuthStore struct {
// contains filtered or unexported fields
}
AuthStore provides API key management for testing. This wraps the internal auth.Store with a public API.
func (*AuthStore) CreateAPIKey ¶ added in v0.8.0
CreateAPIKey creates a new API key and returns the key metadata and token. The token is only returned at creation time and cannot be retrieved later. If key.ID is empty, a random ID will be generated.
func (*AuthStore) DeleteAPIKey ¶ added in v0.8.0
DeleteAPIKey removes an API key by ID.
func (*AuthStore) ListAPIKeys ¶ added in v0.8.0
ListAPIKeys returns all API keys.
type Config ¶
type Config struct {
// DNSAddr is the listen address for the DNS server (e.g., "127.0.0.1:5353").
// If empty, defaults to "127.0.0.1:0" (random port on localhost).
DNSAddr string
// GRPCAddr is the listen address for the gRPC server (e.g., "127.0.0.1:50051").
// If empty, defaults to "127.0.0.1:0" (random port on localhost).
GRPCAddr string
// EnableAuth enables the authentication/authorization interceptor.
// When enabled, clients must provide valid API key tokens via AuthClient().
EnableAuth bool
}
Config configures the test server.
type TestServer ¶
type TestServer struct {
// contains filtered or unexported fields
}
TestServer is an in-process mindns server for testing. It runs both DNS and gRPC servers with an in-memory store.
func NewTestServer ¶
func NewTestServer(cfg Config) (*TestServer, error)
NewTestServer creates a new test server with in-memory storage. Call Start() to begin serving requests.
func (*TestServer) AuthClient ¶ added in v0.8.0
func (s *TestServer) AuthClient(token string) (mindnspb.MindnsServiceClient, *grpc.ClientConn, error)
AuthClient returns a connected gRPC client with authentication for the test server. The token should be a valid API key token (e.g., from AuthStore().Create()). The caller is responsible for closing the connection.
func (*TestServer) AuthStore ¶ added in v0.7.1
func (s *TestServer) AuthStore() *AuthStore
AuthStore returns the auth store for API key management in tests.
func (*TestServer) Client ¶ added in v0.7.1
func (s *TestServer) Client() (mindnspb.MindnsServiceClient, *grpc.ClientConn, error)
Client returns a connected gRPC client for the test server. The caller is responsible for closing the connection. Note: This client has no authentication. Use AuthClient() for authenticated access.
func (*TestServer) CreateZone ¶
func (s *TestServer) CreateZone(ctx context.Context, name string) error
CreateZone is a convenience method to create a test zone.
func (*TestServer) DNSAddr ¶
func (s *TestServer) DNSAddr() string
DNSAddr returns the DNS server address (e.g., "127.0.0.1:5353").
func (*TestServer) GRPCAddr ¶
func (s *TestServer) GRPCAddr() string
GRPCAddr returns the gRPC server address (e.g., "127.0.0.1:50051").
func (*TestServer) Manager ¶
func (s *TestServer) Manager() *zone.Manager
Manager returns the zone manager for direct manipulation in tests.
func (*TestServer) Start ¶
func (s *TestServer) Start() error
Start begins serving DNS and gRPC requests. This method blocks until the server is stopped. For non-blocking operation, call StartBackground().
func (*TestServer) StartAndWait ¶ added in v0.7.1
func (s *TestServer) StartAndWait(ctx context.Context) error
StartAndWait starts the servers in background and waits for them to be ready. This is a convenience method combining StartBackground() and WaitReady().
func (*TestServer) StartBackground ¶
func (s *TestServer) StartBackground()
StartBackground starts the servers in background goroutines. Returns immediately after starting.
func (*TestServer) Stop ¶
func (s *TestServer) Stop(ctx context.Context) error
Stop gracefully stops the test server and releases resources.
func (*TestServer) Store ¶ added in v0.7.1
func (s *TestServer) Store() *store.Store
Store returns the underlying store for direct manipulation in tests.