testhelpers

package
v2.1.155 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAllPromoteStepsSuccessful

func AssertAllPromoteStepsSuccessful(t *testing.T, activities typev1.PipelineActivityInterface, name string)

func AssertHasNoPullRequestForEnv

func AssertHasNoPullRequestForEnv(t *testing.T, activities typev1.PipelineActivityInterface, name string, envName string)

func AssertHasPipelineStatus

func AssertHasPipelineStatus(t *testing.T, activities typev1.PipelineActivityInterface, name string, status v1.ActivityStatusType)

func AssertHasPromoteStatus

func AssertHasPromoteStatus(t *testing.T, activities typev1.PipelineActivityInterface, name string, envName string, status v1.ActivityStatusType)

func AssertHasPullRequestForEnv

func AssertHasPullRequestForEnv(t *testing.T, activities typev1.PipelineActivityInterface, name string, envName string)

func AssertPromoteStep

func AssertPromoteStep(t *testing.T, step *v1.WorkflowStep, expectedEnvironment string)

func AssertSetPullRequestComplete

func AssertSetPullRequestComplete(t *testing.T, provider *gits.FakeProvider, repository *gits.FakeRepository, prNumber int) bool

func AssertSetPullRequestMerged

func AssertSetPullRequestMerged(t *testing.T, provider *gits.FakeProvider, orgName string, repositoryName string,
	prNumber int) bool

AssertSetPullRequestMerged validates that the fake PR has merged

func CleanupTestEnvironmentDir

func CleanupTestEnvironmentDir(o *opts.CommonOptions) error

CleanupTestEnvironmentDir should be called in a deferred function whenever CreateTestEnvironmentDir is called

func CleanupTestJxHomeDir

func CleanupTestJxHomeDir(originalDir, tempDir string) (err error)

CleanupTestJxHomeDir should be called in a deferred function whenever CreateTestJxHomeDir is called

func CleanupTestKubeConfigDir

func CleanupTestKubeConfigDir(originalFile, tempDir string) error

CleanupTestKubeConfigDir should be called in a deferred function whenever CreateTestKubeConfigDir is called

func ConfigureTestOptions

func ConfigureTestOptions(o *opts.CommonOptions, git gits.Gitter, helm helm.Helmer)

ConfigureTestOptions lets configure the options for use in tests using fake APIs to k8s cluster

func ConfigureTestOptionsWithResources

func ConfigureTestOptionsWithResources(o *opts.CommonOptions, k8sObjects []runtime.Object, jxObjects []runtime.Object,
	git gits.Gitter, fakeGitProvider *gits.FakeProvider, helm helm.Helmer, resourcesInstaller resources.Installer)

ConfigureTestOptions lets configure the options for use in tests using fake APIs to k8s cluster.

func CreateTestEnvironmentDir

func CreateTestEnvironmentDir(o *opts.CommonOptions) error

CreateTestEnvironmentDir will create a temporary environment dir for the tests, copying over any existing config, and updating CommonOptions.EnvironmentDir() - this is useful for testing git operations on the environments without clobbering the local environments and risking the cluster getting contaminated - use with gits.GitLocal

func CreateTestJxHomeDir

func CreateTestJxHomeDir() (string, string, error)

CreateTestJxHomeDir creates a temporary JX_HOME directory for the tests, returning the original JX_HOME directory, the temporary JX_HOME value, and any error.

func CreateTestKubeConfigDir

func CreateTestKubeConfigDir() (string, string, error)

CreateTestKubeConfigDir creates a temporary KUBECONFIG directory for the tests, copying over any existing config, returning the original KUBECONFIG value, the temporary KUBECONFIG value, and any error.

func CreateTestPipelineActivity

func CreateTestPipelineActivity(jxClient versioned.Interface, ns string, folder string, repo string, branch string, build string, workflow string) (*v1.PipelineActivity, error)

CreateTestPipelineActivity creates a PipelineActivity with the given arguments

func CreateTestPipelineActivityWithTime

func CreateTestPipelineActivityWithTime(jxClient versioned.Interface, ns string, folder string, repo string, branch string, build string, workflow string, t metav1.Time) (*v1.PipelineActivity, error)

CreateTestPipelineActivityWithTime creates a PipelineActivity with the given timestamp and adds it to the list of activities

func GetFreePort added in v2.1.56

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func LabelSelector added in v2.1.56

func LabelSelector(labels map[string]string) string

LabelSelector builds a Kubernetes label selector from the specified map.

func MockFactoryFakeClients

func MockFactoryFakeClients(mockFactory *clients_test.MockFactory)

MockFactoryFakeClients lets add the fake k8s clients to the factory

func MockFactoryWithKubeClients

func MockFactoryWithKubeClients(mockFactory *clients_test.MockFactory, o *opts.CommonOptions)

MockFactoryWithKubeClients registers the fake clients with the mock factory so they return the same instances

func PortForward added in v2.1.56

func PortForward(namespace string, podName string, containerPort string, forwardPort string, factory clients.Factory) (chan struct{}, error)

PortForward port forwards the container port of the specified pod in the given namespace to the specified local forwarding port. The functions returns a stop channel to stop port forwarding.

func SetFakeFactoryFromKubeClients

func SetFakeFactoryFromKubeClients(o *opts.CommonOptions)

SetFakeFactoryFromKubeClients registers a factory from the existing clients so that if a client is nilled we reuse the same one again

func SetPullRequestClosed

func SetPullRequestClosed(pr *gits.FakePullRequest)

func SetSuccessCommitStatusInPR

func SetSuccessCommitStatusInPR(t *testing.T, repository *gits.FakeRepository, prNumber int)

func WaitForPod added in v2.1.56

func WaitForPod(pod *core_v1.Pod, namespace string, labels map[string]string, timeout time.Duration, kubeClient kubernetes.Interface) error

WaitForPod waits for the specified duration for the given Pod to get into the 'Running' status.

func WaitForPullRequestForEnv

func WaitForPullRequestForEnv(t *testing.T, activities typev1.PipelineActivityInterface, name string, envName string)

Types

type AppTestOptions

type AppTestOptions struct {
	CommonOptions   *opts.CommonOptions
	FakeGitProvider *gits.FakeProvider
	DevRepo         *gits.FakeRepository
	DevEnvRepo      *gits.FakeRepository
	OrgName         string
	DevEnvRepoInfo  *gits.GitRepository
	DevEnv          *jenkinsv1.Environment
	MockHelmer      *helm_test.MockHelmer
	MockFactory     *cmd_test.MockFactory
	MockVaultClient *vault_test.MockClient
	OriginalJxHome  string
	OriginalKubeCfg string
	TempJxHome      string
	TempKubeCfg     string
}

AppTestOptions contains all useful data from the test environment initialized by `prepareInitialPromotionEnv`

func CreateAppTestOptions

func CreateAppTestOptions(gitOps bool, appName string, t assert.TestingT) *AppTestOptions

CreateAppTestOptions configures the mock environment for running apps related tests If you use this function, then don't use t.Parallel

func (*AppTestOptions) AddApp

func (o *AppTestOptions) AddApp(values map[string]interface{}, prefix string) (string, string, string, error)

DirectlyAddApp adds a dummy app using helm

func (*AppTestOptions) Cleanup

func (o *AppTestOptions) Cleanup() error

Cleanup must be run in a defer statement whenever CreateAppTestOptions is run

func (*AppTestOptions) DirectlyAddAppToGitOps

func (o *AppTestOptions) DirectlyAddAppToGitOps(appName string, values map[string]interface{}, prefix string) (name string,
	alias string, version string, err error)

DirectlyAddAppToGitOps modifies the environment git repo directly to add a dummy app

func (*AppTestOptions) GetFullDevEnvDir

func (o *AppTestOptions) GetFullDevEnvDir(envDir string) (name string)

GetFullDevEnvDir returns a dev environment including org name and env

type FakeOut

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

FakeOut can be passed to the Common Options for ease of testing. It's also helpful so test output doesn't get polluted by all the printouts

func (*FakeOut) Fd

func (f *FakeOut) Fd() uintptr

Fd is used to fulfill the terminal Writer interface

func (*FakeOut) GetOutput

func (f *FakeOut) GetOutput() string

GetOutput returns the contents printed to FakeOut

func (*FakeOut) Write

func (f *FakeOut) Write(p []byte) (int, error)

Write is used to fulfill the terminal Writer interface

Jump to

Keyboard shortcuts

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