testing

package
v0.27.6 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionsCheckout = "actions/checkout@v3"
)

Variables

View Source
var Short = testing.Short

Functions

func Getenv

func Getenv(t *testing.T, name string, opts ...string) string

func RandStringBytesRmndr

func RandStringBytesRmndr(n int) string

Copied from https://stackoverflow.com/a/31832326 with thanks

Types

type Bash

type Bash struct {
	runtime.Cmdr
}

func (*Bash) RunScript

func (k *Bash) RunScript(ctx context.Context, path string, cfg ScriptConfig) error

type BuildArg

type BuildArg struct {
	Name, Value string
}

type Config

type Config struct {
	// PreloadImages is the list of container images to be pulled and loaded into the cluster.
	// This might be useful to speed up your test by avoiding to let dockerd pull images from the internet each time you need to
	// run tests.
	PreloadImages []ContainerImage
}

type ContainerImage

type ContainerImage struct {
	Repo, Tag string
}

func Img

func Img(repo, tag string) ContainerImage

type Docker

type Docker struct {
	runtime.Cmdr
}

func (*Docker) Build

func (k *Docker) Build(ctx context.Context, builds []DockerBuild) error

func (*Docker) Push

func (k *Docker) Push(ctx context.Context, images []ContainerImage) error

type DockerBuild

type DockerBuild struct {
	Dockerfile   string
	Args         []BuildArg
	Image        ContainerImage
	EnableBuildX bool
}

type Env

type Env struct {
	Kubeconfig string

	Kubectl *Kubectl
	// contains filtered or unexported fields
}

Env is a testing environment. All of its methods are idempotent so that you can safely call it from within each subtest and you can rerun the individual subtest until it works as you expect.

func Start

func Start(t *testing.T, k8sMinorVer string) *Env

func (*Env) DeleteTestID

func (e *Env) DeleteTestID(t *testing.T)

func (*Env) DockerBuild

func (e *Env) DockerBuild(t *testing.T, builds []DockerBuild)

func (*Env) DockerPush

func (e *Env) DockerPush(t *testing.T, images []ContainerImage)

func (*Env) GetOrGenerateTestID

func (e *Env) GetOrGenerateTestID(t *testing.T) string

func (*Env) KubectlApply

func (e *Env) KubectlApply(t *testing.T, path string, cfg KubectlConfig)

func (*Env) KubectlEnsureClusterRoleBindingServiceAccount

func (e *Env) KubectlEnsureClusterRoleBindingServiceAccount(t *testing.T, bindingName string, clusterrole string, serviceaccount string, cfg KubectlConfig)

func (*Env) KubectlEnsureNS

func (e *Env) KubectlEnsureNS(t *testing.T, name string, cfg KubectlConfig)

func (*Env) KubectlWaitUntilDeployAvailable

func (e *Env) KubectlWaitUntilDeployAvailable(t *testing.T, name string, cfg KubectlConfig)

func (*Env) RunScript

func (e *Env) RunScript(t *testing.T, path string, cfg ScriptConfig)

type GitRepo

type GitRepo struct {
	Dir           string
	Name          string
	CommitMessage string
	Contents      map[string][]byte
	Branch        string

	runtime.Cmdr
}

func (*GitRepo) Sync

func (g *GitRepo) Sync(ctx context.Context) error

type InputSpec

type InputSpec struct {
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
	Default     string `json:"default,omitempty"`
}

type Job

type Job struct {
	RunsOn    string `json:"runs-on"`
	Container string `json:"container,omitempty"`
	Steps     []Step `json:"steps"`
}

type Kind

type Kind struct {
	// Name is the name of the cluster
	Name string

	// Dir is the path to the directory that contains various temporary files like a kind cluster config yaml for testing.
	// This is occasionally the value returned by testing.TempDir() so that
	// you don't need to clean it up yourself.
	Dir string

	runtime.Cmdr
	// contains filtered or unexported fields
}

Kind is a test cluster backend by a kind cluster and the dockerd powering it. It intracts with the kind cluster via the kind command and dockerd via the docker command for various operations that otherwise needs to be automated via shell scripts or makefiles.

func StartKind

func StartKind(t *testing.T, k8sMinorVer string, opts ...Option) *Kind

func (*Kind) Kubeconfig

func (k *Kind) Kubeconfig() string

func (*Kind) LoadImages

func (k *Kind) LoadImages(ctx context.Context, images []ContainerImage) error

func (*Kind) PullImages

func (k *Kind) PullImages(ctx context.Context, images []ContainerImage) error

func (*Kind) Start

func (k *Kind) Start(ctx context.Context, k8sMinorVer string) error

func (*Kind) Stop

func (k *Kind) Stop(ctx context.Context) error

type Kubectl

type Kubectl struct {
	runtime.Cmdr
}

func (*Kubectl) Apply

func (k *Kubectl) Apply(ctx context.Context, path string, cfg KubectlConfig) error

func (*Kubectl) CreateCMLiterals

func (k *Kubectl) CreateCMLiterals(ctx context.Context, name string, literals map[string]string, cfg KubectlConfig) error

func (*Kubectl) CreateClusterRoleBindingServiceAccount

func (k *Kubectl) CreateClusterRoleBindingServiceAccount(ctx context.Context, name string, clusterrole string, sa string, cfg KubectlConfig) error

func (*Kubectl) DeleteCM

func (k *Kubectl) DeleteCM(ctx context.Context, name string, cfg KubectlConfig) error

func (*Kubectl) DeletePods

func (k *Kubectl) DeletePods(ctx context.Context, names []string, cfg KubectlConfig) error

func (*Kubectl) EnsureNS

func (k *Kubectl) EnsureNS(ctx context.Context, name string, cfg KubectlConfig) error

func (*Kubectl) FindPods

func (k *Kubectl) FindPods(ctx context.Context, label string, cfg KubectlConfig) ([]string, error)

func (*Kubectl) GetCMLiterals

func (k *Kubectl) GetCMLiterals(ctx context.Context, name string, cfg KubectlConfig) (map[string]string, error)

func (*Kubectl) GetClusterRoleBinding

func (k *Kubectl) GetClusterRoleBinding(ctx context.Context, name string, cfg KubectlConfig) (string, error)

func (*Kubectl) WaitUntilDeployAvailable

func (k *Kubectl) WaitUntilDeployAvailable(ctx context.Context, name string, cfg KubectlConfig) error

type KubectlConfig

type KubectlConfig struct {
	Env        []string
	NoValidate bool
	Timeout    time.Duration
	Namespace  string
}

func (KubectlConfig) WithTimeout

func (k KubectlConfig) WithTimeout(o time.Duration) KubectlConfig

type On

type On struct {
	Push             *Push             `json:"push,omitempty"`
	WorkflowDispatch *WorkflowDispatch `json:"workflow_dispatch,omitempty"`
}

type Option

type Option = func(*Config)

func Preload

func Preload(imgs ...ContainerImage) Option

type Push

type Push struct {
	Branches []string `json:"branches,omitempty"`
}

type ScriptConfig

type ScriptConfig struct {
	Env []string

	Dir string
}

type Step

type Step struct {
	Name string `json:"name,omitempty"`
	Uses string `json:"uses,omitempty"`
	With *With  `json:"with,omitempty"`
	Run  string `json:"run,omitempty"`
}

type T

type T = testing.T

type With

type With struct {
	Version   string `json:"version,omitempty"`
	GoVersion string `json:"go-version,omitempty"`

	// https://github.com/docker/setup-buildx-action#inputs
	BuildkitdFlags string `json:"buildkitd-flags,omitempty"`
	Install        bool   `json:"install,omitempty"`
	// This can be either the address or the context name
	// https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#description
	Endpoint string `json:"endpoint,omitempty"`
	// Needs to be "docker" in rootless mode
	// https://stackoverflow.com/questions/66142872/how-to-solve-error-with-rootless-docker-in-github-actions-self-hosted-runner-wr
	Driver string `json:"driver,omitempty"`

	// Image is the image arg passed to docker-run-action
	Image string `json:"image,omitempty"`
	// Run is the run arg passed to docker-run-action
	Run string `json:"run,omitempty"`
	// Shell is the shell arg passed to docker-run-action
	Shell string `json:"shell,omitempty"`
}

type Workflow

type Workflow struct {
	Name string         `json:"name"`
	On   On             `json:"on"`
	Jobs map[string]Job `json:"jobs"`
}

type WorkflowDispatch

type WorkflowDispatch struct {
	Inputs map[string]InputSpec `json:"inputs,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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