itest

package
v2.5.8 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const TestUser = "telepresence-test-developer"
View Source
const TestUserAccount = "system:serviceaccount:default:" + TestUser

Variables

This section is empty.

Functions

func AddClusterSuite

func AddClusterSuite(f func(context.Context) suite.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) suite.TestingSuite)

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

func AddHelmAndServiceSuite

func AddHelmAndServiceSuite(suffix, name string, f func(services HelmAndService) suite.TestingSuite)

AddHelmAndServiceSuite adds a constructor for a TestingSuite to the default runner that requires a cluster where a namespace pair has been initialized, a service has been installed, and telepresence has been installed using Helm.

func AddMultipleServicesSuite

func AddMultipleServicesSuite(suffix, name string, f func(services MultipleServices) suite.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) suite.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) suite.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 AppAndMgrNSName

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

func ApplyApp

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

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 GetGlobalHarness

func GetGlobalHarness(ctx context.Context) *cluster

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 LookupEnv

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

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 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 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(t *testing.T)

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 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)

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) context.Context

func WithCluster

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

func WithConfig

func WithConfig(c context.Context, addConfig *client.Config) context.Context

func WithConnection

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

func WithEnv

func WithEnv(ctx context.Context, env map[string]string) context.Context

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

func WithHelmAndService

func WithHelmAndService(h SingleService, f func(HelmAndService))

func WithKubeConfigExtension

func WithKubeConfigExtension(ctx context.Context, extProducer func(*api.Cluster) map[string]interface{}) 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 WithSingleService

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

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

Types

type Cluster

type Cluster interface {
	CapturePodLogs(ctx context.Context, app, container, ns string)
	Executable() string
	GeneralError() error
	GlobalEnv() map[string]string
	InstallTrafficManager(ctx context.Context, managerNamespace string, appNamespaces ...string) error
	IsCI() bool
	Registry() string
	SetGeneralError(error)
	Suffix() string
	TelepresenceVersion() string
	UninstallTrafficManager(ctx context.Context, managerNamespace string)
}

type Harness

type Harness interface {
	Cluster

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

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

func NewContextHarness

func NewContextHarness(ctx context.Context) Harness

type HelmAndService

type HelmAndService interface {
	SingleService
}

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)
	AppNamespace() string
	DeleteSvcAndWorkload(ctx context.Context, workload, name string)
	Kubectl(ctx context.Context, args ...string) error
	KubectlOut(ctx context.Context, args ...string) (string, error)
	ManagerNamespace() string
	RolloutStatusWait(ctx context.Context, workload string) error
}

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 Runner

type Runner interface {
	AddClusterSuite(func(context.Context) suite.TestingSuite)
	AddNamespacePairSuite(suffix string, f func(NamespacePair) suite.TestingSuite)
	AddConnectedSuite(suffix string, f func(NamespacePair) suite.TestingSuite)
	AddHelmAndServiceSuite(suffix, name string, f func(HelmAndService) suite.TestingSuite)
	AddMultipleServicesSuite(suffix, name string, f func(MultipleServices) suite.TestingSuite)
	AddSingleServiceSuite(suffix, name string, f func(SingleService) suite.TestingSuite)
	RunTests(*testing.T)
}

type SingleService

type SingleService interface {
	NamespacePair
	ServiceName() string
}

type Suite

type Suite struct {
	suite.Suite
	Harness
}

func (*Suite) Context

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

Jump to

Keyboard shortcuts

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