helpers

package
v0.0.0-...-5e77798 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SyntheticNodeName is the name given to the "synthetic" node services are
	// registered to.
	SyntheticNodeName = "synthetic-node"
)

Variables

View Source
var EnvoyAdminPort = TCP(30000)

EnvoyAdminPort is the port Consul Dataplane will bind the Envoy admin server to.

Functions

func DNSLookup

func DNSLookup(t *testing.T, suite *Suite, protocol string, serverIP string, serverPort int, host string) []string

func ExpectHTTPAccess

func ExpectHTTPAccess(t *testing.T, ip string, port int)

func ExpectNoHTTPAccess

func ExpectNoHTTPAccess(t *testing.T, ip string, port int)

func GenerateServerTLS

func GenerateServerTLS(t *testing.T, suite *Suite)

GenerateServerTLS generates CA and server certificates/key material and copies them to the suite volume to be used by the server and dataplanes.

func GetEnvoyClusters

func GetEnvoyClusters(t *testing.T, ip string, port int)

func GetMetrics

func GetMetrics(t *testing.T, ip string, port int) string

func TCP

func TCP(n int) nat.Port

func UDP

func UDP(n int) nat.Port

Types

type AuthMethod

type AuthMethod struct {
	Name string
	// contains filtered or unexported fields
}

AuthMethod is a JWT ACL auth-method, that allows us to easily generate bearer tokens in tests.

func NewAuthMethod

func NewAuthMethod(t *testing.T) *AuthMethod

func (*AuthMethod) GenerateToken

func (am *AuthMethod) GenerateToken(t *testing.T, service string) string

GenerateToken generates a JWT bearer token for the given service's identity.

func (*AuthMethod) Register

func (am *AuthMethod) Register(t *testing.T, server *ConsulServer)

Register the auth-method and binding rules with the Consul server.

type ConsulServer

type ConsulServer struct {
	Container *Container
	Client    *api.Client
}

func RunServer

func RunServer(t *testing.T, suite *Suite) *ConsulServer

RunServer runs a Consul server.

func (*ConsulServer) RegisterService

func (s *ConsulServer) RegisterService(t *testing.T, service *api.AgentService)

func (*ConsulServer) RegisterSyntheticNode

func (s *ConsulServer) RegisterSyntheticNode(t *testing.T)

func (*ConsulServer) SetConfigEntry

func (s *ConsulServer) SetConfigEntry(t *testing.T, entry api.ConfigEntry)

type Container

type Container struct {
	testcontainers.Container

	Name        string
	HostIP      string
	ContainerIP string
	MappedPorts map[nat.Port]int
}

func RunDataplane

func RunDataplane(t *testing.T, pod *Pod, suite *Suite, cfg DataplaneConfig) *Container

RunDataplane runs consul-dataplane in the given pod's network. It captures the Envoy proxy's config as an artifact at the end of the test.

func RunService

func RunService(t *testing.T, suite *Suite, pod *Pod, serviceName string) *Container

RunService runs an HTTP echo server in the given pod's network, running on port :8080.

func (*Container) ContainerLogs

func (c *Container) ContainerLogs(t *testing.T) string

ContainerLogs returns the container's logs.

func (*Container) Network

func (c *Container) Network() container.NetworkMode

Network returns the container's network that can be used to join other containers to it.

type ContainerRequest

type ContainerRequest = testcontainers.ContainerRequest

type DataplaneConfig

type DataplaneConfig struct {
	Addresses                     string
	ServiceNodeName               string
	ProxyServiceID                string
	LoginAuthMethod               string
	LoginBearerToken              string
	DNSBindPort                   string
	ServiceMetricsURL             string
	ShutdownGracePeriodSeconds    string
	ShutdownDrainListenersEnabled bool
	DumpEnvoyConfigOnExitEnabled  bool
}

func (DataplaneConfig) ToArgs

func (cfg DataplaneConfig) ToArgs() []string

type Pod

type Pod struct {
	*Container
	// contains filtered or unexported fields
}

func RunPod

func RunPod(t *testing.T, suite *Suite, podName string, mappedPorts []nat.Port) *Pod

RunPod runs a "pause" container with the given ports mapped to the host, the network namespace of which will be joined by other containers. This allows us to know the IP address before starting the "real" container (as is needed to register a sidecar proxy before running consul-dataplane).

func (*Pod) ExposeInternalPorts

func (p *Pod) ExposeInternalPorts(t *testing.T, ports []nat.Port)

ExposeInternalPorts creates iptables rules to forward traffic from public-facing ports to those bound only on the loopback interface. This is useful for testing our DNS proxy which can **only** be bound to the loopback interace.

type Suite

type Suite struct {
	// Name is used as a prefix in container and volume names.
	Name string
	// contains filtered or unexported fields
}

Suite handles the lifecycle of resources (e.g. containers) created during a test, and writes artifacts to disk when the test finishes.

func NewSuite

func NewSuite(t *testing.T, opts SuiteOptions) *Suite

func (*Suite) CaptureArtifact

func (s *Suite) CaptureArtifact(name string, data []byte)

CaptureArtifact stores the given data to be written to disk when the test finishes.

func (*Suite) Context

func (s *Suite) Context(t *testing.T) context.Context

Context returns a context that will be canceled when the test finishes.

func (*Suite) RunContainer

func (s *Suite) RunContainer(t *testing.T, name string, captureLogs bool, req ContainerRequest) *Container

RunContainer runs a container, capturing its logs as artifacts, and stopping the container when the test finishes.

func (*Suite) Volume

func (s *Suite) Volume(t *testing.T) *Volume

Volume returns a Docker volume that can be used to share files between containers. You can also add files from the host using WriteFile. The volume will be deleted when the test finishes.

type SuiteOptions

type SuiteOptions struct {
	// OutputDir is the directory artifacts will be written to. It can be configured
	// using the -output-dir flag.
	OutputDir string

	// DisableReaper controls whether the container reaper is enabled. It can be
	// configured using the -disable-reaper flag.
	//
	// See: https://hub.docker.com/r/testcontainers/ryuk
	DisableReaper bool

	// ServerImage is the container image reference for the Consul server. It can
	// be configured using the -server-image flag.
	ServerImage string

	// ServerVersion is the Consul semver (e.g. v1.x.x-prerelease) used in the image.
	// It is used to determine the capabilities allowed for the version of Consul under test.
	// It can be configured sing the -server-version flag.
	ServerVersion string

	// DataplaneImage is the container image reference for Consul Dataplane. It
	// can be configured using the -dataplane-image flag.
	DataplaneImage string
}

type Volume

type Volume struct {
	types.Volume
	// contains filtered or unexported fields
}

func (*Volume) WriteFile

func (v *Volume) WriteFile(t *testing.T, name string, contents []byte)

WriteFile adds a file to the Volume using a "pause" container.

Jump to

Keyboard shortcuts

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