testenv

package
v0.13.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testenv provides reusable SSH servers and fault injectors for tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrContainerRuntimeUnavailable = errors.New("docker/podman container runtime unavailable")

ErrContainerRuntimeUnavailable means neither Docker nor Podman is usable.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	User       string
	PrivateKey []byte
	PublicKey  ssh.PublicKey
	Signer     ssh.Signer
}

Auth contains a generated client identity and matching SSH configurations.

func NewAuth

func NewAuth(user string) (*Auth, error)

NewAuth generates an Ed25519 client identity for user.

func (*Auth) ClientConfig

func (a *Auth) ClientConfig() *ssh.ClientConfig

ClientConfig returns a client configuration that trusts the ephemeral host.

func (*Auth) ServerConfig

func (a *Auth) ServerConfig(hostKey ssh.Signer) *ssh.ServerConfig

ServerConfig returns a server configuration accepting only this identity.

type ContainerSSHD

type ContainerSSHD struct {
	// contains filtered or unexported fields
}

ContainerSSHD is an isolated OpenSSH fixture managed by Docker or Podman.

func StartContainerSSHD

func StartContainerSSHD(ctx context.Context) (*ContainerSSHD, error)

StartContainerSSHD launches a containerized sshd and waits until it accepts the generated public key. SSH_E2E_IMAGE overrides the fixture image.

func (*ContainerSSHD) Addr

func (c *ContainerSSHD) Addr() string

Addr returns the host-mapped SSH address.

func (*ContainerSSHD) Auth

func (c *ContainerSSHD) Auth() *Auth

Auth returns the generated identity used by the fixture.

func (*ContainerSSHD) ClientConfig

func (c *ContainerSSHD) ClientConfig() *ssh.ClientConfig

ClientConfig returns the matching generated client configuration.

func (*ContainerSSHD) Close

func (c *ContainerSSHD) Close(ctx context.Context) error

Close removes the fixture if it is still present.

func (*ContainerSSHD) Drop

func (c *ContainerSSHD) Drop(ctx context.Context) error

Drop kills the sshd container, deterministically dropping its connections.

func (*ContainerSSHD) Freeze

func (c *ContainerSSHD) Freeze(ctx context.Context) error

Freeze pauses every process in the container without dropping TCP state.

func (*ContainerSSHD) Resume

func (c *ContainerSSHD) Resume(ctx context.Context) error

Resume resumes a container paused by Freeze.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an in-process SSH server listening on a real loopback socket.

func Start

func Start(auth *Auth) (*Server, error)

Start starts an SSH server authenticated by auth. Session exec requests are run with the host's /bin/sh, which makes the fixture useful for integration tests without requiring an external sshd.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server's loopback address.

func (*Server) Close

func (s *Server) Close() error

Close stops the listener and every active transport.

func (*Server) Drop

func (s *Server) Drop()

Drop closes every currently established TCP connection without stopping the listener. New connections can be established immediately afterward.

func (*Server) Freeze

func (s *Server) Freeze()

Freeze prevents the server from answering subsequent SSH requests while leaving transports established. Calls are idempotent.

func (*Server) Resume

func (s *Server) Resume()

Resume releases requests blocked by Freeze. Calls are idempotent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL