itest

package
v2.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestUser = "telepresence-test-developer"
)

Variables

View Source
var ExtendClusterFunc = func(c Cluster) Cluster {
	return c
}

Functions

func AddClusterSuite

func AddClusterSuite(f func(context.Context) TestingSuite)

AddClusterSuite adds a constructor for a test suite that requires a cluster to run to the default runner.

func AddConnectedSuite

func AddConnectedSuite(suffix string, f func(NamespacePair) TestingSuite)

AddConnectedSuite adds a constructor for a test suite to the default runner that requires a cluster where a namespace pair has been initialized, and telepresence is connected.

func AddMultipleServicesSuite

func AddMultipleServicesSuite(suffix, name string, f func(services MultipleServices) TestingSuite)

AddMultipleServicesSuite adds a constructor for a test suite to the default runner that requires a cluster where a namespace pair has been initialized, multiple services has been installed, and telepresence is connected.

func AddNamespacePairSuite

func AddNamespacePairSuite(suffix string, f func(NamespacePair) TestingSuite)

AddNamespacePairSuite adds a constructor for a test suite that requires a cluster where a namespace pair has been initialized to the default runner.

func AddSingleServiceSuite

func AddSingleServiceSuite(suffix, name string, f func(services SingleService) TestingSuite)

AddSingleServiceSuite adds a constructor for a test suite to the default runner that requires a cluster where a namespace pair has been initialized, a service has been installed, and telepresence is connected.

func AddTrafficManagerSuite added in v2.13.0

func AddTrafficManagerSuite(suffix string, f func(NamespacePair) TestingSuite)

AddTrafficManagerSuite adds a constructor for a test suite that requires a cluster where a namespace pair has been initialized and a traffic manager is installed.

func AppAndMgrNSName

func AppAndMgrNSName(suffix string) (appNS, mgrNS string)

func ApplyApp

func ApplyApp(ctx context.Context, name, namespace, workload string)

ApplyApp calls kubectl apply -n <namespace> -f on the given app + .yaml found in testdata/k8s relative to the directory returned by GetWorkingDir.

func ApplyAppTemplate added in v2.18.0

func ApplyAppTemplate(ctx context.Context, namespace string, app *AppData)

ApplyAppTemplate calls kubectl apply -n <namespace> -f on the given app + .yaml found in testdata/k8s relative to the directory returned by GetWorkingDir.

func ApplyEchoService

func ApplyEchoService(ctx context.Context, name, namespace string, port int)

func ApplyService

func ApplyService(ctx context.Context, name, namespace, image string, port, targetPort int)

func AssertDisconnectOutput added in v2.5.0

func AssertDisconnectOutput(ctx context.Context, stdout string)

AssertDisconnectOutput asserts that the stdout contains the correct output from a telepresence quit command.

func AssertQuitOutput

func AssertQuitOutput(ctx context.Context, stdout string)

AssertQuitOutput asserts that the stdout contains the correct output from a telepresence quit command.

func Command

func Command(ctx context.Context, executable string, args ...string) *dexec.Cmd

Command creates and returns a dexec.Cmd initialized with the global environment from the cluster harness and any other environment that has been added using the WithEnv() function.

func CreateNamespaces

func CreateNamespaces(ctx context.Context, namespaces ...string)

func DeleteNamespaces

func DeleteNamespaces(ctx context.Context, namespaces ...string)

func DeleteSvcAndWorkload

func DeleteSvcAndWorkload(ctx context.Context, workload, name, namespace string)

func EnvironMap added in v2.17.0

func EnvironMap(ctx context.Context) dos.MapEnv

func GetModuleRoot added in v2.9.3

func GetModuleRoot(ctx context.Context) string

func GetOSSRoot added in v2.9.3

func GetOSSRoot(ctx context.Context) string

func GetUser

func GetUser(ctx context.Context) string

func GetWorkingDir

func GetWorkingDir(ctx context.Context) string

func KubeConfig

func KubeConfig(ctx context.Context) string

func Kubectl

func Kubectl(ctx context.Context, namespace string, args ...string) error

Kubectl runs kubectl with the default context and the given namespace, or in the default namespace if the given namespace is an empty string.

func KubectlOut

func KubectlOut(ctx context.Context, namespace string, args ...string) (string, error)

KubectlOut runs kubectl with the default context and the application namespace and returns its combined output.

func LoadEnv added in v2.12.1

func LoadEnv(ctx context.Context) context.Context

func LookupEnv

func LookupEnv(ctx context.Context, key string) (value string, ok bool)

func OpenTemplate added in v2.13.0

func OpenTemplate(ctx context.Context, name string, data any) (io.Reader, error)

func Output

func Output(ctx context.Context, exe string, args ...string) (string, error)

Output runs the given command and arguments and returns its combined output and an error if the command failed.

func PingInterceptedEchoServer added in v2.6.8

func PingInterceptedEchoServer(ctx context.Context, svc, svcPort string, headers ...string)

PingInterceptedEchoServer assumes that a server has been created using StartLocalHttpEchoServer and that an intercept is active for the given svc and svcPort that will redirect to that local server.

func PodCreateTimeout added in v2.5.8

func PodCreateTimeout(c context.Context) time.Duration

PodCreateTimeout will return a timeout suitable for operations that create pods. This is longer when running against clusters that scale up nodes on demand for new pods.

func ReadTemplate added in v2.16.1

func ReadTemplate(ctx context.Context, name string, data any) ([]byte, error)

func RolloutStatusWait

func RolloutStatusWait(ctx context.Context, namespace, workload string) error

func Run

func Run(ctx context.Context, exe string, args ...string) error

Run runs the given command and arguments and returns an error if the command failed.

func RunError

func RunError(err error, out []byte) error

RunError checks if the given err is a *exit.ExitError, and if so, extracts Stderr and the ExitCode from it.

func RunTests

func RunTests(c context.Context)

func RunningPods added in v2.6.5

func RunningPods(ctx context.Context, svc, ns string) []string

RunningPods return the names of running pods with app=<service name>. Running here means that at least one container is still running. I.e. the pod might well be terminating but still considered running.

func SetConfig added in v2.14.1

func SetConfig(ctx context.Context, configDir, configYml string) (context.Context, error)

SetConfig creates a config from the configYml provided and assigns it to a new context which is returned. Use this if you are testing components of the config.yml, otherwise you can use setDefaultConfig.

func SetModuleRoot added in v2.9.3

func SetModuleRoot(ctx context.Context, dir string) context.Context

SetModuleRoot sets the module root for the given context to dir.

func SetOSSRoot added in v2.9.3

func SetOSSRoot(ctx context.Context, dir string) context.Context

SetOSSRoot sets the OSS module root for the given context to dir.

func StartLocalHttpEchoServer

func StartLocalHttpEchoServer(ctx context.Context, name string) (int, context.CancelFunc)

StartLocalHttpEchoServer starts a local http server that echoes a line with the given name and the current URL path. The port is returned together with function that cancels the server.

func StartLocalHttpEchoServerWithHost added in v2.13.0

func StartLocalHttpEchoServerWithHost(ctx context.Context, name string, host string) (int, context.CancelFunc)

StartLocalHttpEchoServerWithHost is like StartLocalHttpEchoServer but binds to a specific host instead of localhost.

func Telepresence

func Telepresence(ctx context.Context, args ...string) (string, string, error)

Telepresence executes the CLI command in a new process.

func TelepresenceCmd

func TelepresenceCmd(ctx context.Context, args ...string) *dexec.Cmd

TelepresenceCmd creates a dexec.Cmd using the Command function. Before the command is created, the environment is extended with DEV_TELEPRESENCE_CONFIG_DIR from filelocation.AppUserConfigDir and DEV_TELEPRESENCE_LOG_DIR from filelocation.AppUserLogDir.

func TelepresenceDisconnectOk added in v2.5.0

func TelepresenceDisconnectOk(ctx context.Context, args ...string)

TelepresenceDisconnectOk tells telepresence to quit and asserts that the stdout contains the correct output.

func TelepresenceOk

func TelepresenceOk(ctx context.Context, args ...string) string

TelepresenceOk executes the CLI command in a new process and requires the result to be OK.

func TelepresenceQuitOk

func TelepresenceQuitOk(ctx context.Context)

TelepresenceQuitOk tells telepresence to quit and asserts that the stdout contains the correct output.

func TestContext

func TestContext(t *testing.T, ossRoot, moduleRoot string) context.Context

func WithAgentImage added in v2.13.0

func WithAgentImage(ctx context.Context, image *Image) context.Context

func WithClientImage added in v2.17.0

func WithClientImage(ctx context.Context, image *Image) context.Context

func WithCluster

func WithCluster(ctx context.Context, f func(ctx context.Context))

func WithConfig

func WithConfig(c context.Context, modifierFunc func(config client.Config)) context.Context

func WithConnected added in v2.13.0

func WithConnected(np NamespacePair, f func(ctx context.Context, ch NamespacePair))

func WithEnv

func WithEnv(ctx context.Context, env dos.MapEnv) context.Context

WithEnv adds environment variables to be used by the Command function.

func WithImage added in v2.13.0

func WithImage(ctx context.Context, image *Image) context.Context

func WithKubeConfig added in v2.17.0

func WithKubeConfig(ctx context.Context, cfg *api.Config) context.Context

func WithKubeConfigExtension

func WithKubeConfigExtension(ctx context.Context, extProducer func(*api.Cluster) map[string]any) context.Context

func WithModuleRoot

func WithModuleRoot(ctx context.Context) context.Context

WithModuleRoot set the working directory for the Command function to the module root.

func WithMultipleServices

func WithMultipleServices(np NamespacePair, name string, serviceCount int, f func(MultipleServices))

func WithNamespacePair

func WithNamespacePair(ctx context.Context, suffix string, f func(NamespacePair))

func WithNamespaces added in v2.13.0

func WithNamespaces(ctx context.Context, namespaces *Namespaces) context.Context

func WithOSSRoot added in v2.9.3

func WithOSSRoot(ctx context.Context) context.Context

WithOSSRoot set the working directory for the Command function to the OSS module root.

func WithSingleService

func WithSingleService(h NamespacePair, serviceName string, f func(SingleService))

func WithT added in v2.13.0

func WithT(ctx context.Context, t *testing.T) context.Context

func WithTrafficManager added in v2.13.0

func WithTrafficManager(np NamespacePair, f func(ctx context.Context, ch NamespacePair))

func WithUser

func WithUser(ctx context.Context, clusterUser string) context.Context

func WithWorkingDir

func WithWorkingDir(ctx context.Context, dir string) context.Context

WithWorkingDir determines the working directory for the Command function.

func WrapSensitive added in v2.14.1

func WrapSensitive(s string) string

WrapSensitive wraps an argument sent to Command so that it doesn't get logged verbatim. This can be used for commands like "telepresence login --apikey NNNN" where the NNN shouldn't be visible in the logs. If NNN Is wrapped using this function, it will appear as "***" in the logs.

Types

type AppData added in v2.18.0

type AppData struct {
	ServiceName    string
	DeploymentName string
	AppName        string
	ContainerName  string
	Image          string
	PullPolicy     string
	Ports          []AppPort
	Env            map[string]string
}

type AppPort added in v2.18.0

type AppPort struct {
	ServicePortName   string
	ServicePortNumber uint16
	TargetPortName    string
	TargetPortNumber  uint16
	Protocol          string
	AppProtocol       string
}

type Assertions added in v2.16.1

type Assertions struct {
	*assert.Assertions
}

func (*Assertions) EventuallyContext added in v2.16.1

func (r *Assertions) EventuallyContext(ctx context.Context, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...any) bool

type Cluster

type Cluster interface {
	CapturePodLogs(ctx context.Context, app, container, ns string)
	CompatVersion() string
	Executable() string
	GeneralError() error
	GlobalEnv(context.Context) dos.MapEnv
	AgentVersion(context.Context) string
	Initialize(context.Context) context.Context
	InstallTrafficManager(ctx context.Context, values map[string]string) error
	InstallTrafficManagerVersion(ctx context.Context, version string, values map[string]string) error
	IsCI() bool
	IsIPv6() bool
	Registry() string
	SetGeneralError(error)
	Suffix() string
	TelepresenceVersion() string
	UninstallTrafficManager(ctx context.Context, managerNamespace string, args ...string)
	PackageHelmChart(ctx context.Context) (string, error)
	GetValuesForHelm(ctx context.Context, values map[string]string, release bool) []string
	GetK8SCluster(ctx context.Context, context, managerNamespace string) (context.Context, *k8s.Cluster, error)
	TelepresenceHelmInstall(ctx context.Context, upgrade bool, args ...string) error
	UserdPProf() uint16
	RootdPProf() uint16
}

func GetGlobalHarness

func GetGlobalHarness(ctx context.Context) Cluster

type Harness

type Harness interface {
	Cluster

	PushHarness(ctx context.Context, setup func(ctx context.Context) bool, tearDown func(ctx context.Context))
	RunSuite(TestingSuite)

	HarnessContext() context.Context
	SetupSuite()
	HarnessT() *testing.T
	PopHarness()
}

func NewContextHarness

func NewContextHarness(ctx context.Context) Harness

type Image added in v2.13.0

type Image struct {
	Name     string `json:"name"`
	Tag      string `json:"tag,omitempty"`
	Registry string `json:"registry,omitempty"`
}

func GetAgentImage added in v2.13.0

func GetAgentImage(ctx context.Context) *Image

func GetClientImage added in v2.17.0

func GetClientImage(ctx context.Context) *Image

func GetImage added in v2.13.0

func GetImage(ctx context.Context) *Image

func ImageFromEnv added in v2.17.0

func ImageFromEnv(ctx context.Context, env, defaultTag, defaultRegistry string) *Image

func (*Image) FQName added in v2.17.0

func (img *Image) FQName() string

type MultipleServices

type MultipleServices interface {
	NamespacePair
	Name() string
	ServiceCount() int
}

type NamespacePair

type NamespacePair interface {
	Harness
	ApplyApp(ctx context.Context, name, workload string)
	ApplyEchoService(ctx context.Context, name string, port int)
	ApplyTemplate(ctx context.Context, path string, values any)
	DeleteTemplate(ctx context.Context, path string, values any)
	AppNamespace() string
	TelepresenceConnect(ctx context.Context, args ...string) string
	DeleteSvcAndWorkload(ctx context.Context, workload, name string)
	Kubectl(ctx context.Context, args ...string) error
	KubectlOk(ctx context.Context, args ...string) string
	KubectlOut(ctx context.Context, args ...string) (string, error)
	ManagerNamespace() string
	RollbackTM(ctx context.Context)
	RolloutStatusWait(ctx context.Context, workload string) error
}

type Namespaces added in v2.13.0

type Namespaces struct {
	Namespace         string   `json:"namespace,omitempty"`
	ManagedNamespaces []string `json:"managedNamespaces,omitempty"`
}

func GetNamespaces added in v2.13.0

func GetNamespaces(ctx context.Context) *Namespaces

func (*Namespaces) HelmString added in v2.13.0

func (n *Namespaces) HelmString() string

func (*Namespaces) UniqueList added in v2.13.0

func (n *Namespaces) UniqueList() []string

type Profile added in v2.5.8

type Profile string
const (
	DefaultProfile      Profile = "default"
	GkeAutopilotProfile Profile = "gke-autopilot"
)

func GetProfile added in v2.5.8

func GetProfile(ctx context.Context) Profile

type Requirements added in v2.16.1

type Requirements struct {
	*require.Assertions
}

func (*Requirements) EventuallyContext added in v2.16.1

func (r *Requirements) EventuallyContext(ctx context.Context, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...any)

type Runner

type Runner interface {
	AddClusterSuite(func(context.Context) TestingSuite)
	AddNamespacePairSuite(suffix string, f func(NamespacePair) TestingSuite)
	AddTrafficManagerSuite(suffix string, f func(NamespacePair) TestingSuite)
	AddConnectedSuite(suffix string, f func(NamespacePair) TestingSuite)
	AddMultipleServicesSuite(suffix, name string, f func(MultipleServices) TestingSuite)
	AddSingleServiceSuite(suffix, name string, f func(SingleService) TestingSuite)
	RunTests(context.Context)
}

type SingleService

type SingleService interface {
	NamespacePair
	ServiceName() string
}

type StatusResponse added in v2.16.1

type StatusResponse struct {
	RootDaemon          *cmd.RootDaemonStatus          `json:"root_daemon,omitempty"`
	UserDaemon          *cmd.UserDaemonStatus          `json:"user_daemon,omitempty"`
	TrafficManager      *cmd.TrafficManagerStatus      `json:"traffic_manager,omitempty"`
	ContainerizedDaemon *cmd.ContainerizedDaemonStatus `json:"daemon,omitempty"`
	Connections         []struct {
		RootDaemon          *cmd.RootDaemonStatus          `json:"root_daemon,omitempty"`
		UserDaemon          *cmd.UserDaemonStatus          `json:"user_daemon,omitempty"`
		TrafficManager      *cmd.TrafficManagerStatus      `json:"traffic_manager,omitempty"`
		ContainerizedDaemon *cmd.ContainerizedDaemonStatus `json:"daemon,omitempty"`
	} `json:"connections,omitempty"`
	Error string `json:"err,omitempty"`
}

func TelepresenceStatus added in v2.16.1

func TelepresenceStatus(ctx context.Context, args ...string) (*StatusResponse, error)

func TelepresenceStatusOk added in v2.16.1

func TelepresenceStatusOk(ctx context.Context, args ...string) *StatusResponse

type Suite

type Suite struct {
	suite.Suite
	Harness
}

func (*Suite) Assert added in v2.16.1

func (s *Suite) Assert() *Assertions

func (*Suite) Context

func (s *Suite) Context() context.Context

func (*Suite) Require added in v2.16.1

func (s *Suite) Require() *Requirements

type TestingSuite added in v2.13.0

type TestingSuite interface {
	suite.TestingSuite
	Harness
	Context() context.Context
	Assert() *Assertions
	Require() *Requirements
	SuiteName() string
}

Jump to

Keyboard shortcuts

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