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
- func ListenNgrok(t *testing.T, c NgrokTunnelConfig) (ngrok.Tunnel, error)
- func PollUntil(t *testing.T, condition func() bool, timeout time.Duration)
- func RequireDatadogMetrics(t *testing.T, query string, ...)
- type Chatwork
- type ChatworkAccount
- type ChatworkMessage
- type ChatworkMessagePostResult
- type ChatworkMessages
- type ChatworkResponse
- type ChatworkRoom
- type ChatworkRoomConfig
- type ChatworkRoomOption
- type ChatworkRoomProvider
- type Config
- type ECRImageRepository
- type ECRImageRepositoryConfig
- type ECRImageRepositoryOption
- type ECRImageRepositoryProvider
- type EKSCTLProvider
- type EKSCluster
- type EKSClusterConfig
- type EKSClusterOption
- type EKSClusterProvider
- type EnvProvider
- func (p *EnvProvider) Cleanup() error
- func (p *EnvProvider) GetChatworkRoom(_ ...ChatworkRoomOption) (*ChatworkRoom, error)
- func (p *EnvProvider) GetEKSCluster(_ ...EKSClusterOption) (*EKSCluster, error)
- func (p *EnvProvider) GetGitHubRepository(_ ...GitHubRepositoryOption) (*GitHubRepository, error)
- func (p *EnvProvider) GetS3Bucket(_ ...S3BucketOption) (*S3Bucket, error)
- func (p *EnvProvider) GetSlackChannel(_ ...SlackChannelOption) (*SlackChannel, error)
- func (p *EnvProvider) Setup() error
- type GitHubRepository
- type GitHubRepositoryConfig
- type GitHubRepositoryOption
- type GitHubRepositoryProvider
- type GitHubWritableRepositoriesEnvProvider
- type GitHubWritableRepositoriesProvider
- type GitHubWritableRepository
- type GitHubWritableRepositoryConfig
- type GitHubWritableRepositoryOption
- type Helm
- type HelmConfig
- type HelmOption
- type KindProvider
- type Kubeconfig
- type KubeconfigCluster
- type KubeconfigContext
- type KubeconfigUser
- type Kubectl
- type KubectlProvider
- func (p *KubectlProvider) Cleanup() error
- func (p *KubectlProvider) KubernetesConfigMap(opts ...KubernetesConfigMapOption) (*KubernetesConfigMap, error)
- func (p *KubectlProvider) KubernetesNamespace(opts ...KubernetesNamespaceOption) (*KubernetesNamespace, error)
- func (p *KubectlProvider) Setup() error
- type Kubernetes
- type KubernetesCluster
- type KubernetesClusterConfig
- type KubernetesClusterOption
- type KubernetesClusterProvider
- type KubernetesConfigMap
- type KubernetesConfigMapConfig
- type KubernetesConfigMapOption
- type KubernetesConfigMapProvider
- type KubernetesNamespace
- type KubernetesNamespaceConfig
- type KubernetesNamespaceOption
- type KubernetesNamespaceProvider
- type KubernetesNode
- type NgrokTunnelConfig
- type Option
- type Provider
- type S3Bucket
- type S3BucketClient
- func (c *S3BucketClient) Delete(t *testing.T, key string)
- func (c *S3BucketClient) GetLatestString(t *testing.T, prefix string) string
- func (c *S3BucketClient) GetString(t *testing.T, key string) string
- func (c *S3BucketClient) ListKeys(t *testing.T, prefix string) []string
- func (c *S3BucketClient) PutString(t *testing.T, key, value string)
- type S3BucketConfig
- type S3BucketOption
- type S3BucketProvider
- type SlackChannel
- type SlackChannelConfig
- type SlackChannelOption
- type SlackChannelProvider
- type SlackMessaging
- type SlackMessagingClient
- type TerraformProvider
- func (p *TerraformProvider) Cleanup() error
- func (p *TerraformProvider) GetECRImageRepository(opts ...ECRImageRepositoryOption) (*ECRImageRepository, error)
- func (p *TerraformProvider) GetEKSCluster(opts ...EKSClusterOption) (*EKSCluster, error)
- func (p *TerraformProvider) GetKubernetesCluster(opts ...KubernetesClusterOption) (*KubernetesCluster, error)
- func (p *TerraformProvider) GetS3Bucket(opts ...S3BucketOption) (*S3Bucket, error)
- func (p *TerraformProvider) Setup() error
- type TestKit
- func (tk *TestKit) ChatworkRoom(t *testing.T, opts ...ChatworkRoomOption) *ChatworkRoom
- func (tk *TestKit) Cleanup(t *testing.T)
- func (tk *TestKit) CleanupNeeded(failed bool) bool
- func (tk *TestKit) DoCleanup() []error
- func (tk *TestKit) ECRImageRepository(t *testing.T, opts ...ECRImageRepositoryOption) *ECRImageRepository
- func (tk *TestKit) EKSCluster(t *testing.T, opts ...EKSClusterOption) *EKSCluster
- func (tk *TestKit) GitHubRepository(t *testing.T, opts ...GitHubRepositoryOption) *GitHubRepository
- func (tk *TestKit) GitHubWritableRepository(t *testing.T, opts ...GitHubWritableRepositoryOption) *GitHubWritableRepository
- func (tk *TestKit) KubernetesCluster(t *testing.T, opts ...KubernetesClusterOption) *KubernetesCluster
- func (tk *TestKit) KubernetesClusterProvider() (KubernetesClusterProvider, error)
- func (tk *TestKit) KubernetesConfigMap(t *testing.T, opts ...KubernetesConfigMapOption) *KubernetesConfigMap
- func (tk *TestKit) KubernetesNamespace(t *testing.T, opts ...KubernetesNamespaceOption) *KubernetesNamespace
- func (tk *TestKit) S3Bucket(t *testing.T, opts ...S3BucketOption) *S3Bucket
- func (tk *TestKit) SlackChannel(t *testing.T, opts ...SlackChannelOption) *SlackChannel
Constants ¶
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
ListenNgrok establishes an ngrok tunnel and listens for incoming HTTP requests. The caller is responsible for closing the returned listener.
func RequireDatadogMetrics ¶ added in v0.10.0
func RequireDatadogMetrics(t *testing.T, query string, validate func(datadogV1.MetricsQueryMetadata) error)
RequireDatadogMetrics queries metrics from Datadog and validates them.
query can be a query string like the following examples: - "avg:kubernetes.cpu.user.total{*}" - "system.cpu.idle{*}"
validate is called for each series in the response. The test fails if any of the validate calls return an error. The test fails also if the query returns no series.
Types ¶
type Chatwork ¶
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 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 ChatworkRoomConfig ¶
type ChatworkRoomConfig struct {
ID string
}
type ChatworkRoomOption ¶
type ChatworkRoomOption func(*ChatworkRoomConfig)
type ChatworkRoomProvider ¶
type ChatworkRoomProvider interface {
GetChatworkRoom(opts ...ChatworkRoomOption) (*ChatworkRoom, error)
}
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 ¶
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 (p *GitHubWritableRepositoriesEnvProvider) Cleanup() error
func (*GitHubWritableRepositoriesEnvProvider) GetGitHubWritableRepository ¶ added in v0.8.0
func (p *GitHubWritableRepositoriesEnvProvider) GetGitHubWritableRepository(opts ...GitHubWritableRepositoryOption) (*GitHubWritableRepository, error)
func (*GitHubWritableRepositoriesEnvProvider) Setup ¶ added in v0.8.0
func (p *GitHubWritableRepositoriesEnvProvider) Setup() error
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 (*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 HelmOption ¶ added in v0.2.0
type HelmOption func(*HelmConfig)
type KindProvider ¶
type KindProvider struct { // Wait for control plane node to be ready (default 0s) Wait time.Duration // node docker image to use for booting the cluster Image string // ConfigPath is the path to a kind configuration file ConfigPath string // Retain retains nodes for debugging when cluster creation fails Retain bool log.L // 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 KubeconfigContext ¶
type KubeconfigUser ¶
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 ¶
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 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 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 RetainResources ¶
func RetainResources() Option
func RetainResourcesOnFailure ¶
func RetainResourcesOnFailure() Option
type S3Bucket ¶
type S3Bucket struct {
Region, Name string
// contains filtered or unexported fields
}
type S3BucketClient ¶
func NewS3BucketClient ¶
func NewS3BucketClient(awsConfig aws.Config, bucket string) *S3BucketClient
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
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 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
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 ¶
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 ¶
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
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
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
Source Files ¶
- chatwork.go
- datadog.go
- helm.go
- kubectl.go
- kubernetes.go
- ngrok.go
- plugin_eksctl.go
- plugin_env.go
- plugin_github_repositories.go
- plugin_kind.go
- plugin_kubectl.go
- plugin_terraform.go
- poll_until.go
- resource_chatwork.go
- resource_ecrimagerepo.go
- resource_ekscluster.go
- resource_github.go
- resource_github_writeable_repo.go
- resource_k8s_configmap.go
- resource_k8s_namespace.go
- resource_kubernetes_cluster.go
- resource_s3bucket.go
- resource_slack.go
- s3bucket_client.go
- slack.go
- testkit.go