tester

package
v1.0.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const TestRegistryAlias = "PORTER_TEST_REGISTRY_ALIAS"

TestRegistryAlias is the environment variable that contains a pre-configured hostname alias that can be used to access localhost. This environment variable is only set in on the linux and macos CI agents so that we can test a variant of communicating with a registry that is unsecured but is not obviously "localhost" or 127.0.0.1.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestRegistry

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

TestRegistry is a temporary registry that is stopped when the test completes.

func (*TestRegistry) Close

func (t *TestRegistry) Close()

Close stops the registry.

func (*TestRegistry) String

func (t *TestRegistry) String() string

String prints the registry URI.

type TestRegistryOptions

type TestRegistryOptions struct {
	// UseTLS indicates the registry should use http, secured with a self-signed certificate.
	UseTLS bool

	// UseAlias indicates that when the TestRegistryAlias environment variable is set,
	// the registry address use the hostname alias, and not localhost.
	UseAlias bool
}

TestRegistryOptions controls how a test registry is run.

type Tester

type Tester struct {

	// TestContext is a porter context for the filesystem.
	TestContext *portercontext.TestContext

	// TestDir is the temp directory created for the test.
	TestDir string

	// PorterHomeDir is the temp PORTER_HOME directory for the test.
	PorterHomeDir string

	// RepoRoot is the root of the porter repository.
	// Useful for constructing paths that won't break when the test is moved.
	RepoRoot string

	// T is the test helper.
	T *testing.T
	// contains filtered or unexported fields
}

func NewTest

func NewTest(t *testing.T) (Tester, error)

NewTest sets up for a smoke test.

Always defer Tester.Close(), even when an error is returned.

func NewTestWithConfig

func NewTestWithConfig(t *testing.T, configFilePath string) (Tester, error)

NewTestWithConfig sets up for a smoke test using the specified Porter config file. The path should be either be absolute, or relative to the repository root.

Always defer Tester.Close(), even when an error is returned.

func (Tester) ApplyTestBundlePrerequisites

func (t Tester) ApplyTestBundlePrerequisites()

ApplyTestBundlePrerequisites ensures that anything required by the test bundle, mybuns, is ready to use.

func (Tester) Chdir

func (t Tester) Chdir(dir string)

func (Tester) Close

func (t Tester) Close()

func (Tester) CurrentNamespace

func (t Tester) CurrentNamespace() string

CurrentNamespace configured in Porter's config file

func (Tester) EditYaml

func (t Tester) EditYaml(path string, transformations ...func(yq *yaml.Editor) error)

EditYaml applies a set of yq transformations to a file.

func (Tester) ListInstallations

func (t Tester) ListInstallations(allNamespaces bool, namespace string, name string, labels []string) ([]porter.DisplayInstallation, error)

func (Tester) MakeTestBundle

func (t Tester) MakeTestBundle(name string, ref string)

func (Tester) PrepareTestBundle

func (t Tester) PrepareTestBundle()

PrepareTestBundle ensures that the mybuns test bundle is ready to use.

func (*Tester) RequireFileMode

func (t *Tester) RequireFileMode(path string, mode os.FileMode)

RequireFileMode checks that all files in the specified path match the specifed file mode. Uses a glob pattern to match.

func (Tester) RequireInstallationExists

func (t Tester) RequireInstallationExists(namespace string, name string) porter.DisplayInstallation

func (Tester) RequireInstallationInList

func (t Tester) RequireInstallationInList(namespace, name string, list []storage.Installation) storage.Installation

func (Tester) RequireInstallationNotFound

func (t Tester) RequireInstallationNotFound(namespace string, name string)

func (Tester) RequireNotFoundReturned

func (t Tester) RequireNotFoundReturned(err error)

func (Tester) RequirePorter

func (t Tester) RequirePorter(args ...string) (stdout string, combinedoutput string)

Run a porter command and fail the test if the command returns an error.

func (Tester) RunPorter

func (t Tester) RunPorter(args ...string) (stdout string, combinedoutput string, err error)

RunPorter executes a porter command returning stderr when it fails.

func (Tester) RunPorterWith

func (t Tester) RunPorterWith(opts ...func(*shx.PreparedCommand)) (stdout string, combinedoutput string, err error)

RunPorterWith works like RunPorter, but you can customize the command before it's run.

func (Tester) ShowInstallation

func (t Tester) ShowInstallation(namespace string, name string) (porter.DisplayInstallation, error)

func (Tester) StartTestRegistry

func (t Tester) StartTestRegistry(opts TestRegistryOptions) *TestRegistry

StartTestRegistry runs an OCI registry in a container, returning details about the registry. The registry is cleaned up by default when the test completes.

Jump to

Keyboard shortcuts

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