Documentation
¶
Overview ¶
Package lapitest provides utilities for black-box testing of LocalAPI (ipnserver).
Index ¶
- func NewBackend(tb testing.TB, opts ...Option) *ipnlocal.LocalBackend
- func NewUnreachableControlClient(tb testing.TB, opts controlclient.Options) (controlclient.Client, error)
- type Client
- type NewControlFn
- type Option
- type Server
- func (s *Server) Backend() *ipnlocal.LocalBackend
- func (s *Server) BlockWhileInUse(ctx context.Context) error
- func (s *Server) BlockWhileInUseByOther(ctx context.Context, actor ipnauth.Actor) error
- func (s *Server) CheckCurrentUser(want ipnauth.Actor)
- func (s *Server) Client() *Client
- func (s *Server) ClientFor(actor ipnauth.Actor) *Client
- func (s *Server) ClientWithName(name string) *Client
- func (s *Server) Close()
- func (s *Server) MakeTestActor(name string, clientID string) *ipnauth.TestActor
- func (s *Server) Start()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBackend ¶
func NewBackend(tb testing.TB, opts ...Option) *ipnlocal.LocalBackend
NewBackend returns a new ipnlocal.LocalBackend for testing purposes. It fails the test if the specified options are invalid or if the backend cannot be created.
func NewUnreachableControlClient ¶
func NewUnreachableControlClient(tb testing.TB, opts controlclient.Options) (controlclient.Client, error)
NewUnreachableControlClient is a NewControlFn that creates a new controlclient.Client for an unreachable control server.
Types ¶
type Client ¶
type Client struct { // Client is the underlying [local.Client] wrapped by the test client. // It is configured to send requests to the test server on behalf of the actor. *local.Client // Actor represents the user on whose behalf this client is making requests. // The server uses it to determine the client's identity and permissions. // The test can mutate the user to alter the actor's identity or permissions // before making a new request. It is typically an [ipnauth.TestActor], // unless the [Client] was created with s specific actor using [Server.ClientFor]. Actor ipnauth.Actor // contains filtered or unexported fields }
Client wraps a local.Client for testing purposes. It can be created using Server.Client, Server.ClientWithName, or Server.ClientFor and sends requests as the specified actor to the associated Server.
func (*Client) WatchIPNBus ¶
func (c *Client) WatchIPNBus(ctx context.Context, mask ipn.NotifyWatchOpt) (*local.IPNBusWatcher, context.CancelFunc)
WatchIPNBus is like local.Client.WatchIPNBus but returns a local.IPNBusWatcher that is closed when the test ends and a cancel function that stops the watcher. It fails the test if the underlying WatchIPNBus returns an error.
type NewControlFn ¶
type NewControlFn func(tb testing.TB, opts controlclient.Options) (controlclient.Client, error)
NewControlFn is any function that creates a new controlclient.Client with the specified options.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is any optional configuration that can be passed to NewServer or NewBackend.
func WithBackend ¶
func WithBackend(backend *ipnlocal.LocalBackend) Option
WithBackend returns an Option that configures the server to use the specified ipnlocal.LocalBackend instead of creating a new one. It is mutually exclusive with WithControlClient.
func WithContext ¶
WithContext returns an Option that sets the base context to be used by the Server.
func WithControlClient ¶
func WithControlClient(newControl NewControlFn) Option
WithControlClient returns an option that specifies a function to be used by the ipnlocal.LocalBackend when creating a new controlclient.Client. It is mutually exclusive with WithBackend and is only used if no backend has been provided.
func WithLogging ¶
WithLogging returns an Option that enables or disables logging.
func WithSys ¶
WithSys returns an Option that sets the tsd.System to be used when creating a new ipnlocal.LocalBackend.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server is an in-process LocalAPI server that can be used in end-to-end tests.
func NewUnstartedServer ¶
NewUnstartedServer returns a new Server with the specified options without starting it.
func (*Server) Backend ¶
func (s *Server) Backend() *ipnlocal.LocalBackend
Backend returns the underlying ipnlocal.LocalBackend.
func (*Server) BlockWhileInUse ¶
BlockWhileInUse blocks until the server becomes idle (no active requests), or the context is done. It returns the context's error if it is done. It is used in tests only.
func (*Server) BlockWhileInUseByOther ¶
BlockWhileInUseByOther blocks while the specified actor can't connect to the server due to another actor being connected. It is used in tests only.
func (*Server) CheckCurrentUser ¶
CheckCurrentUser fails the test if the current user does not match the expected user. It is only used on Windows and will be removed as we progress on tailscale/corp#18342.
func (*Server) Client ¶
Client returns a new Client configured for making requests to the server as a new ipnauth.TestActor with a unique username and ipnauth.ClientID.
func (*Server) ClientFor ¶
ClientFor returns a new Client configured for making requests to the server as the specified actor.
func (*Server) ClientWithName ¶
ClientWithName returns a new Client configured for making requests to the server as a new ipnauth.TestActor with the specified name and a unique ipnauth.ClientID.
func (*Server) Close ¶
func (s *Server) Close()
Close shuts down the server and blocks until all outstanding requests on this server have completed.
func (*Server) MakeTestActor ¶
MakeTestActor returns a new ipnauth.TestActor with the specified name and client ID. If the name is empty, a unique sequential name is generated. Likewise, if clientID is empty, a unique sequential client ID is generated.