testkit

package module
v0.9.0 Latest Latest
Warning

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

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

README

mumoshu/testkit

mumoshu/testkit is a toolkit for writing Go tests for your cloud applications.

Currently, this provides the following tools:

  • Abstraction over terraform/eksctl/envvars/kubectl/k8s-kind so that you can provision/retain/destroy the cloud test harness for max developer productivity
  • Various helpers for writing test assertions against cloud resources

It is handy when you want to write an integration or E2E tests for:

  • Kubernetes controllers
  • Terraform workspaces
  • ChatOps bots
  • Complex CI/CD workflows
  • AWS CDK projects (Planned)
  • Pulumi projects (Planned)

See testkit_test.go for inspiration on how you would write tests with testkit.

Documentation

Overview

mumoshu/testkit is a set of tools for testing your application and/or infrastructure code end-to-end.

For application testing, it can provision a real infrastructure in the cloud, runs your code on it, and verifies the results. It supports AWS EKS and S3, GitHub, Slack.

For infrastructure testing, it calls Terraform, eksctl, etc., of your choice to provision the infrastructure, optionally deploy test agents on it, and finally runs your tests against it.

It is designed to abstract away and automate the common patterns of testing infrastructure code, so that you can focus on writing the actual tests.

For example, it can delegate the creation of an EKS cluster to eksctl, and other resources to Terraform, and then run your tests against them. It can also create a GitHub repository, push your code to it, and then run your tests against it.

Index

Constants

View Source
const (
	EnvChatworkRoomID = "TESTKIT_CHATWORK_ROOM_ID"
	EnvChatworkToken  = "TESTKIT_CHATWORK_TOKEN"

	DefaultChatworkEndpoint = "https://api.chatwork.com/v2"

	MessagesPath = "/rooms/%s/messages"
)

Variables

This section is empty.

Functions

func ListenNgrok added in v0.8.0

func ListenNgrok(t *testing.T, c NgrokTunnelConfig) (ngrok.Tunnel, error)

ListenNgrok establishes an ngrok tunnel and listens for incoming HTTP requests. The caller is responsible for closing the returned listener.

func PollUntil added in v0.2.0

func PollUntil(t *testing.T, condition func() bool, timeout time.Duration)

Types

type Chatwork

type Chatwork struct {
	Endpoint string
	Token    string
}

func (*Chatwork) GetMessages

func (c *Chatwork) GetMessages(roomID string) (ChatworkMessages, error)

func (*Chatwork) PostMessage

func (c *Chatwork) PostMessage(roomID, message string) (*ChatworkMessagePostResult, error)

type ChatworkAccount

type ChatworkAccount struct {
	AccountID      uint64 `json:"account_id"`
	Name           string `json:"name"`
	AvatarImageURL string `json:"avatar_image_url"`
}

type ChatworkMessage

type ChatworkMessage struct {
	MessageID  string          `json:"message_id"`
	Account    ChatworkAccount `json:"account"`
	Body       string          `json:"body"`
	SendTime   uint64          `json:"send_time"`
	UpdateTime uint64          `json:"update_time"`
}

type ChatworkMessagePostResult

type ChatworkMessagePostResult struct {
	MessageID string `json:"message_id"`
}

type ChatworkMessages

type ChatworkMessages []ChatworkMessage

type ChatworkResponse

type ChatworkResponse struct {
	Errors []string `json:"errors"`
}

type ChatworkRoom

type ChatworkRoom struct {
	ID    string
	Token string
}

type ChatworkRoomConfig

type ChatworkRoomConfig struct {
	ID string
}

type ChatworkRoomOption

type ChatworkRoomOption func(*ChatworkRoomConfig)

type ChatworkRoomProvider

type ChatworkRoomProvider interface {
	GetChatworkRoom(opts ...ChatworkRoomOption) (*ChatworkRoom, error)
}

type Config

type Config struct {
	Providers                []Provider
	RetainResources          bool
	RetainResourcesOnFailure bool
}

type ECRImageRepository

type ECRImageRepository struct {
	// ID is the name of the ECR image repository.
	// In case the ARN is:
	// 	arn:aws:ecr:${REGION}:${ACCOUNT_ID}:repository/testkit-imagerep
	// the ID is:
	// 	testkit-imagerep
	ID string `json:"id"`
	// ARN is the Amazon Resource Name of the ECR image repository.
	// In case the name of the repository is "testkit-imagerep",
	// the ARN is:
	// 	arn:aws:ecr:${REGION}:${ACCOUNT_ID}:repository/testkit-imagerep
	ARN string `json:"arn"`
	// RepositoryURL is the URL of the ECR image repository.
	// In case the name of the repository is "testkit-imagerep",
	// the URL is:
	// 	${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/testkit-imagerep
	RepositoryURL string `json:"repository_url"`
	// RegistryID is the ID of the registry.
	// It's the same as the account ID.
	RegistryID string `json:"registry_id"`
}

ECRImageRepository is an ECR image repository that is provided by the TestKit. It doesn't necessarily be created by the TestKit, but it can be created by other tools, such as eksctl.

type ECRImageRepositoryConfig

type ECRImageRepositoryConfig struct {
	// The ID is the local name of the repository in the test,
	// which is used by the provider implmentation to identify
	// the repository in the test.
	// The ID is usually not the same as the name of the repository.
	ID string
}

ECRImageRepositoryOptions is the options for creating an ECR image repository. The zero value is a valid value.

type ECRImageRepositoryOption

type ECRImageRepositoryOption func(*ECRImageRepositoryConfig)

type ECRImageRepositoryProvider

type ECRImageRepositoryProvider interface {
	// GetECRImageRepository returns an ECR image repository.
	GetECRImageRepository(opts ...ECRImageRepositoryOption) (*ECRImageRepository, error)
}

ECRImageRepositoryProvider is a provider that can provision an ECR image repository. Any provider that can create an ECR image repository should implement this interface.

type EKSCTLProvider

type EKSCTLProvider struct {
	// ConfigPath is the path to the eksctl config file.
	ConfigPath string
}

func (*EKSCTLProvider) Cleanup

func (p *EKSCTLProvider) Cleanup() error

func (*EKSCTLProvider) GetEKSCluster

func (p *EKSCTLProvider) GetEKSCluster(opts ...EKSClusterOption) (*EKSCluster, error)

func (*EKSCTLProvider) Setup

func (p *EKSCTLProvider) Setup() error

type EKSCluster

type EKSCluster struct {
	Endpoint       string
	KubeconfigPath string
}

EKSCluster is an EKS cluster that is provided by the TestKit. It doesn't necessarily be created by the TestKit, but it can be created by other tools, such as eksctl.

type EKSClusterConfig

type EKSClusterConfig struct {
	// The ID is the local name of the cluster in the test,
	// which is used by the provider implmentation to identify
	// the cluster in the test.
	// The ID is usually not the same as the name of the cluster.
	ID string
}

EKSClusterOptions is the options for creating an EKS cluster. The zero value is a valid value.

type EKSClusterOption

type EKSClusterOption func(*EKSClusterConfig)

type EKSClusterProvider

type EKSClusterProvider interface {
	// GetEKSCluster returns an EKS cluster.
	GetEKSCluster(opts ...EKSClusterOption) (*EKSCluster, error)
}

EKSClusterProvider is a provider that can provision an EKS cluster. Any provider that can create an EKS cluster should implement this interface.

type EnvProvider

type EnvProvider struct {
}

func (*EnvProvider) Cleanup

func (p *EnvProvider) Cleanup() error

func (*EnvProvider) GetChatworkRoom

func (p *EnvProvider) GetChatworkRoom(_ ...ChatworkRoomOption) (*ChatworkRoom, error)

func (*EnvProvider) GetEKSCluster

func (p *EnvProvider) GetEKSCluster(_ ...EKSClusterOption) (*EKSCluster, error)

func (*EnvProvider) GetGitHubRepository

func (p *EnvProvider) GetGitHubRepository(_ ...GitHubRepositoryOption) (*GitHubRepository, error)

func (*EnvProvider) GetS3Bucket

func (p *EnvProvider) GetS3Bucket(_ ...S3BucketOption) (*S3Bucket, error)

func (*EnvProvider) GetSlackChannel

func (p *EnvProvider) GetSlackChannel(_ ...SlackChannelOption) (*SlackChannel, error)

func (*EnvProvider) Setup

func (p *EnvProvider) Setup() error

type GitHubRepository

type GitHubRepository struct {
	ID string
	// Name is the name of the repository.
	// This is the name that appears in the URL.
	// For example, if the URL is
	// https://github.com/mumoshu/example-repo,
	// then the name is "mumoshu/example-repo".
	Name string

	// Token is the GitHub personal access token.
	// This is used to authenticate to GitHub API for interacting
	// with the repository.
	Token string
}

type GitHubRepositoryConfig

type GitHubRepositoryConfig struct {
	ID string
}

type GitHubRepositoryOption

type GitHubRepositoryOption func(*GitHubRepositoryConfig)

type GitHubRepositoryProvider

type GitHubRepositoryProvider interface {
	GetGitHubRepository(opts ...GitHubRepositoryOption) (*GitHubRepository, error)
}

type GitHubWritableRepositoriesEnvProvider added in v0.8.0

type GitHubWritableRepositoriesEnvProvider struct {
}

GitHubWritableRepositoriesEnvProvider is a provider that behaves as a registory of writeable GitHub repositories. The repositories are reigstered via TESTKIT_GITHUB_WRITEABLE_REPOS variable, which is a comma-separated list of `owner/name` of GitHub repositories. The provider implementation never creates a new repository.

The repository to be returned needs to be writeable, which means that the repository's testkit-config branch contains ".testkit.writeable" file in its root directory.

The branch and the file requirement is there to avoid accidentally modifying the repository that is not intended to be modified.

This is useful for testing the behavior of the code that modifies the repository AND you don't want to accidentally modify the repository that is not intended to be modified.

func (*GitHubWritableRepositoriesEnvProvider) Cleanup added in v0.8.0

func (*GitHubWritableRepositoriesEnvProvider) GetGitHubWritableRepository added in v0.8.0

func (*GitHubWritableRepositoriesEnvProvider) Setup added in v0.8.0

type GitHubWritableRepositoriesProvider added in v0.8.0

type GitHubWritableRepositoriesProvider interface {
	GetGitHubWritableRepository(opts ...GitHubWritableRepositoryOption) (*GitHubWritableRepository, error)
}

type GitHubWritableRepository added in v0.8.0

type GitHubWritableRepository struct {
	ID string
	// Name is the name of the repository.
	// This is the name that appears in the URL.
	// For example, if the URL is
	// https://github.com/mumoshu/example-repo,
	// then the name is "mumoshu/example-repo".
	Name string

	// Token is the GitHub personal access token.
	// This is used to authenticate to GitHub API for interacting
	// with the repository.
	Token string

	git.Service
}

type GitHubWritableRepositoryConfig added in v0.8.0

type GitHubWritableRepositoryConfig struct {
	ID string
}

type GitHubWritableRepositoryOption added in v0.8.0

type GitHubWritableRepositoryOption func(*GitHubWritableRepositoryConfig)

type Helm added in v0.2.0

type Helm struct {
	// KubeconfigPath is the path to the kubeconfig file.
	KubeconfigPath string
}

func NewHelm added in v0.2.0

func NewHelm(kubeconfigPath string) *Helm

func (*Helm) AddRepo added in v0.4.0

func (k *Helm) AddRepo(t *testing.T, repoName, repoURL string)

func (*Helm) Capture added in v0.2.0

func (k *Helm) Capture(t *testing.T, args ...string) string

func (*Helm) UpgradeOrInstall added in v0.2.0

func (k *Helm) UpgradeOrInstall(t *testing.T, releaseName, chartPath string, opts ...HelmOption)

type HelmConfig added in v0.2.0

type HelmConfig struct {
	ExtraArgs []string
	Namespace string
	Values    map[string]interface{}
}

type HelmOption added in v0.2.0

type HelmOption func(*HelmConfig)

type KindProvider

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

func (*KindProvider) Cleanup

func (p *KindProvider) Cleanup() error

func (*KindProvider) GetKubernetesCluster

func (p *KindProvider) GetKubernetesCluster(opts ...KubernetesClusterOption) (*KubernetesCluster, error)

func (*KindProvider) Setup

func (p *KindProvider) Setup() error

type Kubeconfig

type Kubeconfig struct {
	APIVersion     string              `yaml:"apiVersion"`
	Clusters       []KubeconfigCluster `yaml:"clusters"`
	Contexts       []KubeconfigContext `yaml:"contexts"`
	CurrentContext string              `yaml:"current-context"`
	Kind           string              `yaml:"kind"`
	Preferences    struct {
	} `yaml:"preferences"`
	Users []KubeconfigUser `yaml:"users"`
}

type KubeconfigCluster

type KubeconfigCluster struct {
	Cluster struct {
		Server                   string `yaml:"server"`
		CertificateAuthorityData string `yaml:"certificate-authority-data"`
	} `yaml:"cluster"`
	Name string `yaml:"name"`
}

type KubeconfigContext

type KubeconfigContext struct {
	Context struct {
		Cluster string `yaml:"cluster"`
		User    string `yaml:"user"`
	} `yaml:"context"`
	Name string `yaml:"name"`
}

type KubeconfigUser

type KubeconfigUser struct {
	Name string `yaml:"name"`
	User struct {
		Exec struct {
			APIVersion string   `yaml:"apiVersion"`
			Command    string   `yaml:"command"`
			Args       []string `yaml:"args"`
		} `yaml:"exec"`
	} `yaml:"user"`
}

type Kubectl

type Kubectl struct {
	// KubeconfigPath is the path to the kubeconfig file.
	KubeconfigPath string

	// LogError controls whether to log the error returned by kubectl.
	// Currently, this is respected that doesn't return the error,
	// like the `Failed` method.
	LogError bool
}

func NewKubectl

func NewKubectl(kubeconfigPath string) *Kubectl

func (*Kubectl) Capture

func (k *Kubectl) Capture(t *testing.T, args ...string) string

func (*Kubectl) Failed added in v0.7.0

func (k *Kubectl) Failed(t *testing.T, args ...string) bool

Failed runs kubectl with the given args and returns true if it fails. This is useful for e.g. asserting that a resource does not exist.

type KubectlProvider

type KubectlProvider struct {
	// DefaultKubeconfigPath is the path to the kubeconfig file.
	DefaultKubeconfigPath string
	// contains filtered or unexported fields
}

func (*KubectlProvider) Cleanup

func (p *KubectlProvider) Cleanup() error

func (*KubectlProvider) KubernetesConfigMap

func (p *KubectlProvider) KubernetesConfigMap(opts ...KubernetesConfigMapOption) (*KubernetesConfigMap, error)

func (*KubectlProvider) KubernetesNamespace

func (p *KubectlProvider) KubernetesNamespace(opts ...KubernetesNamespaceOption) (*KubernetesNamespace, error)

func (*KubectlProvider) Setup

func (p *KubectlProvider) Setup() error

type Kubernetes added in v0.2.0

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

func NewKubernetes added in v0.2.0

func NewKubernetes(kubeconfigPath string) *Kubernetes

func (*Kubernetes) GetNodes added in v0.2.0

func (k *Kubernetes) GetNodes(t *testing.T) []KubernetesNode

GetNodes returns the nodes in the cluster. It's useful when you want to test your app that adds, removes, updates, or refers to nodes.

func (*Kubernetes) ListReadyNodeNames added in v0.2.0

func (k *Kubernetes) ListReadyNodeNames(t *testing.T) []string

ListReadyNodeNames returns the names of the nodes that are ready. It's useful when you want to test your app that adds or removes nodes.

The readiness of a node is determined by the status of the node. A node is ready if the status of the node has a condition of type "Ready" and the status is "True".

type KubernetesCluster

type KubernetesCluster struct {
	// KubeconfigPath is the path to the kubeconfig file.
	KubeconfigPath string
}

type KubernetesClusterConfig

type KubernetesClusterConfig struct {
	ID string
}

type KubernetesClusterOption

type KubernetesClusterOption func(*KubernetesClusterConfig)

type KubernetesClusterProvider

type KubernetesClusterProvider interface {
	GetKubernetesCluster(...KubernetesClusterOption) (*KubernetesCluster, error)
}

type KubernetesConfigMap

type KubernetesConfigMap struct {
	Namespace string
	Name      string
}

type KubernetesConfigMapConfig

type KubernetesConfigMapConfig struct {
	ID             string
	Namespace      string
	KubeconfigPath string
}

type KubernetesConfigMapOption

type KubernetesConfigMapOption func(*KubernetesConfigMapConfig)

func KubernetesConfigMapKubeconfigPath

func KubernetesConfigMapKubeconfigPath(path string) KubernetesConfigMapOption

func KubernetesConfigMapNamespace

func KubernetesConfigMapNamespace(namespace string) KubernetesConfigMapOption

type KubernetesConfigMapProvider

type KubernetesConfigMapProvider interface {
	KubernetesConfigMap(opts ...KubernetesConfigMapOption) (*KubernetesConfigMap, error)
}

KubernetesConfigMapProvider is a provider that can provision an Kubernetes ConfigMap. Any provider that can create a ConfigMap should implement this interface.

type KubernetesNamespace

type KubernetesNamespace struct {
	Name string
}

type KubernetesNamespaceConfig

type KubernetesNamespaceConfig struct {
	ID             string
	KubeconfigPath string
}

type KubernetesNamespaceOption

type KubernetesNamespaceOption func(*KubernetesNamespaceConfig)

func KubeconfigPath

func KubeconfigPath(path string) KubernetesNamespaceOption

type KubernetesNamespaceProvider

type KubernetesNamespaceProvider interface {
	KubernetesNamespace(opts ...KubernetesNamespaceOption) (*KubernetesNamespace, error)
}

KubernetesNamespaceProvider is a provider that can provision an Kubernetes namespace. Any provider that can create an S3 bucket should implement this interface.

type KubernetesNode added in v0.2.0

type KubernetesNode struct {
	Metadata kubernetesMetadata   `json:"metadata"`
	Status   kubernetesNodeStatus `json:"status"`
}

func (*KubernetesNode) IsReady added in v0.2.0

func (n *KubernetesNode) IsReady() bool

type NgrokTunnelConfig added in v0.8.0

type NgrokTunnelConfig struct {
	// EdgeLabel is the label of the ngrok edge to use.
	//
	// Let's say you want to establish an ngrok tunnel to your local HTTP server running on port 80,
	// you will usually run the following command to establish the tunnel:
	//   ngrok tunnel --label edge=edghts_<some randomish id> http://localhost:80
	//
	// In this case, the edge label is "edghts_<some randomish id>".
	EdgeLabel string

	// The URL of the ngrok tunnel endpoint.
	// This needs to be the one that corresponds to the edge associated to the edge label.
	EndpointURL string

	// Token is the ngrok authtoken.
	Token string
}

func NgrokConfigFromEnv added in v0.8.0

func NgrokConfigFromEnv() NgrokTunnelConfig

type Option

type Option func(*Config)

func Providers

func Providers(providers ...Provider) Option

func RetainResources

func RetainResources() Option

func RetainResourcesOnFailure

func RetainResourcesOnFailure() Option

type Provider

type Provider interface {
	Setup() error
	Cleanup() error
}

type S3Bucket

type S3Bucket struct {
	Region, Name string
	// contains filtered or unexported fields
}

func (*S3Bucket) AWSV2Config

func (s *S3Bucket) AWSV2Config(t *testing.T) aws.Config

type S3BucketClient

type S3BucketClient struct {
	S3Svc  *s3.Client
	Bucket string
}

func NewS3BucketClient

func NewS3BucketClient(awsConfig aws.Config, bucket string) *S3BucketClient

func (*S3BucketClient) Delete

func (c *S3BucketClient) Delete(t *testing.T, key string)

func (*S3BucketClient) GetLatestString added in v0.2.0

func (c *S3BucketClient) GetLatestString(t *testing.T, prefix string) string

GetLatestString returns the latest object in the bucket with the given prefix. The returned string is the content of the object. "Latest" means the object with the latest LastModified timestamp.

func (*S3BucketClient) GetString

func (c *S3BucketClient) GetString(t *testing.T, key string) string

func (*S3BucketClient) ListKeys added in v0.2.0

func (c *S3BucketClient) ListKeys(t *testing.T, prefix string) []string

ListKeys returns the keys of the objects in the bucket with the given prefix.

func (*S3BucketClient) PutString

func (c *S3BucketClient) PutString(t *testing.T, key, value string)

type S3BucketConfig

type S3BucketConfig struct {
	ID string
}

type S3BucketOption

type S3BucketOption func(*S3BucketConfig)

type S3BucketProvider

type S3BucketProvider interface {
	GetS3Bucket(opts ...S3BucketOption) (*S3Bucket, error)
}

S3BucketProvider is a provider that can provision an S3 bucket. Any provider that can create an S3 bucket should implement this interface.

type SlackChannel

type SlackChannel struct {
	// ID is the name of the Slack channel.
	ID                 string
	BotToken           string
	AppToken           string
	IncomingWebhookURL string

	SlackMessaging
}

type SlackChannelConfig

type SlackChannelConfig struct {
	ID string
}

type SlackChannelOption

type SlackChannelOption func(*SlackChannelConfig)

type SlackChannelProvider

type SlackChannelProvider interface {
	GetSlackChannel(opts ...SlackChannelOption) (*SlackChannel, error)
}

type SlackMessaging added in v0.8.0

type SlackMessaging interface {
	SendMessage(t *testing.T, message string)
}

type SlackMessagingClient added in v0.8.0

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

func NewSlackMessagingClient added in v0.8.0

func NewSlackMessagingClient(token, channel string) *SlackMessagingClient

func (*SlackMessagingClient) SendMessage added in v0.8.0

func (c *SlackMessagingClient) SendMessage(t *testing.T, message string)

type TerraformProvider

type TerraformProvider struct {
	// WorkspacePath is the path to the Terraform workspace.
	WorkspacePath string
	// Vars is the map of Terraform variables.
	Vars map[string]string

	// KubeconfigDir is the directory where the kubeconfig files for EKS clusters are stored.
	KubeconfigDir string
	// contains filtered or unexported fields
}

func (*TerraformProvider) Cleanup

func (p *TerraformProvider) Cleanup() error

func (*TerraformProvider) GetECRImageRepository

func (p *TerraformProvider) GetECRImageRepository(opts ...ECRImageRepositoryOption) (*ECRImageRepository, error)

func (*TerraformProvider) GetEKSCluster

func (p *TerraformProvider) GetEKSCluster(opts ...EKSClusterOption) (*EKSCluster, error)

func (*TerraformProvider) GetKubernetesCluster added in v0.3.0

func (p *TerraformProvider) GetKubernetesCluster(opts ...KubernetesClusterOption) (*KubernetesCluster, error)

func (*TerraformProvider) GetS3Bucket

func (p *TerraformProvider) GetS3Bucket(opts ...S3BucketOption) (*S3Bucket, error)

func (*TerraformProvider) Setup

func (p *TerraformProvider) Setup() error

type TestKit

type TestKit struct {
	Config
	// contains filtered or unexported fields
}

func Build added in v0.8.0

func Build(opts ...Option) (*TestKit, error)

Build creates a new TestKit harness. This is a variant of New that does not automatically clean up the resources and does not fail the test if it cannot create the TestKit.

It's preferrable to use New instead of this function if you are writing a test that does not share the test harness with other tests.

If you do want to share the test harness with other tests, you can use this function like this:

func TestMain(m *testing.M) {
	var opts []testkit.Option
	tk, err := testkit.Build(opts...)
	if err != nil {
		log.Fatalf("failed to create TestKit: %v", err)
	}
	defer tk.Cleanup()

	os.Exit(m.Run())
}

func New

func New(t *testing.T, opts ...Option) *TestKit

New creates a new TestKit harness. It fails the test if it cannot create the TestKit. It automatically cleans up all the resources created by the TestKit at the end of the test.

If the RetainResources option is true, it does not clean up the resources. This is useful for debugging. If the RetainResourcesOnFailure option is true, it does not clean up the resources if the test fails. This is useful for debugging.

If the Providers option is not empty, it uses the providers specified in the option.

If providers is empty, it uses the default providers. The default providers are the providers that are available in the current environment. Availability of a provider is determined by the Setup method. If no provider is available, it fails the test.

func (*TestKit) ChatworkRoom

func (tk *TestKit) ChatworkRoom(t *testing.T, opts ...ChatworkRoomOption) *ChatworkRoom

func (*TestKit) Cleanup

func (tk *TestKit) Cleanup(t *testing.T)

Cleanup cleans up all the resources created by the TestKit. The caller should call this function at the end of the test, typically in a defer statement. If the TestKit is created with the RetainResources option, this function does nothing.

func (*TestKit) CleanupNeeded added in v0.6.0

func (tk *TestKit) CleanupNeeded(failed bool) bool

CleanupNeeded returns true if the test harness needs to be cleaned up.

This takes into account the RetainResources and RetainResourcesOnFailure options and the test result. If the RetainResources option is true, it returns false. If the RetainResourcesOnFailure option is true and the test failed, it returns false. Otherwise, it returns true.

This is useful when you want to clean up resources unmanaged by the TestKit respecting the RetainResources and RetainResourcesOnFailure options.

func (*TestKit) DoCleanup added in v0.9.0

func (tk *TestKit) DoCleanup() []error

DoCleanup cleans up all the resources created by the TestKit. It returns a list of errors that occurred during the cleanup. The caller should call this function at the end of the test. Note that this function does not respect the RetainResources and RetainResourcesOnFailure options. If you want to respect these options, use the Cleanup function instead.

func (*TestKit) ECRImageRepository

func (tk *TestKit) ECRImageRepository(t *testing.T, opts ...ECRImageRepositoryOption) *ECRImageRepository

ECRImageRepository creates an ECR image repository.

func (*TestKit) EKSCluster

func (tk *TestKit) EKSCluster(t *testing.T, opts ...EKSClusterOption) *EKSCluster

EKSCluster creates an EKS cluster.

func (*TestKit) GitHubRepository

func (tk *TestKit) GitHubRepository(t *testing.T, opts ...GitHubRepositoryOption) *GitHubRepository

GitHubRepository creates a GitHub repository. The repository is created by the provider implementation. The provider implementation may create a new repository, or may use an existing repository. The provider implementation may also create a new GitHub personal access token, or may use an existing one. It iterates over the available providers and calls the GetGitHubRepository method on each provider. If no provider implements GetGitHubRepository, it fails the test. If multiple providers implement GetGitHubRepository, it returns the first successful one. If multiple providers implement GetGitHubRepository and all of them fail, it fails the test.

func (*TestKit) GitHubWritableRepository added in v0.8.0

func (tk *TestKit) GitHubWritableRepository(t *testing.T, opts ...GitHubWritableRepositoryOption) *GitHubWritableRepository

GitHubWritableRepository retrieves a writable GitHub repository.

It iterates over the available providers and calls the GetGitHubWritableRepository method on each provider. If no provider implements GetGitHubWritableRepository, it fails the test. If multiple providers implement GetGitHubWritableRepository, it returns the first successful one. If multiple providers implement GetGitHubWritableRepository and all of them fail, it fails the test.

func (*TestKit) KubernetesCluster

func (tk *TestKit) KubernetesCluster(t *testing.T, opts ...KubernetesClusterOption) *KubernetesCluster

func (*TestKit) KubernetesClusterProvider added in v0.8.2

func (tk *TestKit) KubernetesClusterProvider() (KubernetesClusterProvider, error)

func (*TestKit) KubernetesConfigMap

func (tk *TestKit) KubernetesConfigMap(t *testing.T, opts ...KubernetesConfigMapOption) *KubernetesConfigMap

KubernetesConfigMap returns a KubernetesConfigMap. It does so by iterating over the available providers and calling the KubernetesConfigMap method on each provider. If no provider implements KubernetesConfigMap, it fails the test. If multiple providers implement KubernetesConfigMap, it returns the first successful one. If multiple providers implement KubernetesConfigMap and all of them fail, it fails the test.

func (*TestKit) KubernetesNamespace

func (tk *TestKit) KubernetesNamespace(t *testing.T, opts ...KubernetesNamespaceOption) *KubernetesNamespace

KubernetesNamespace returns a KubernetesNamespace. It does so by iterating over the available providers and calling the KubernetesNamespace method on each provider. If no provider implements KubernetesNamespace, it fails the test. If multiple providers implement KubernetesNamespace, it returns the first successful one. If multiple providers implement KubernetesNamespace and all of them fail, it fails the test.

func (*TestKit) S3Bucket

func (tk *TestKit) S3Bucket(t *testing.T, opts ...S3BucketOption) *S3Bucket

func (*TestKit) SlackChannel

func (tk *TestKit) SlackChannel(t *testing.T, opts ...SlackChannelOption) *SlackChannel

Directories

Path Synopsis
testapps

Jump to

Keyboard shortcuts

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