test

package
v0.0.0-...-3566972 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const ToolsImageName = "aks-periscope-test-tools"

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterAccess

type ClusterAccess struct {
	ClientConfig   *rest.Config
	Clientset      *kubernetes.Clientset
	KubeConfigFile *os.File
}

ClusterAccess groups the objects used for connecting to a cluster as a single user/serviceaccount.

func (*ClusterAccess) GetKubeConfigBinding

func (clusterAccess *ClusterAccess) GetKubeConfigBinding() string

GetKubeConfigBinding gets the Docker volume binding required to map the fixture's kubeconfig file to the expected location in the testing tools container.

type ClusterFixture

type ClusterFixture struct {
	NamespaceSuffix string
	KnownNamespaces *KnownNamespaces
	CommandRunner   *ToolsCommandRunner
	AdminAccess     *ClusterAccess
	PeriscopeAccess *ClusterAccess
}

ClusterFixture holds all information required to connect to a local cluster, generated on the fly for testing purposes. It supports running arbitrary command-line tools available via a locally-built Docker image containing any desired tools for test setup.

func GetClusterFixture

func GetClusterFixture() (*ClusterFixture, error)

GetClusterFixture can be called from test files, and will always return the same instance of the Fixture (per test process).

func (*ClusterFixture) CheckDockerImages

func (fixture *ClusterFixture) CheckDockerImages() error

CheckDockerImages checks our list of required images is up-to-date based on images stored in the cluster's nodes. If any images are superfluous or missing it will return an error specifying the image tags that need to be added or removed. It also verifies the pull policies to ensure that no unnecessary downloading of images occurs during test runs.

func (*ClusterFixture) Cleanup

func (fixture *ClusterFixture) Cleanup()

Cleanup is intended to be called after all tests have run. It does not delete the cluster itself, because re-creating it is an expensive operation, and the goal here is to allow fast re-runs when testing locally.

func (*ClusterFixture) CreateTestNamespace

func (fixture *ClusterFixture) CreateTestNamespace(prefix string) (string, error)

CreateTestNamespace creates a Kuberenetes namespace with a suffix that changes for each test run,and a well-known label. The label is used for cleanup purposes, so that it is easy to identify which namespaces have been created for testing and delete just those. The suffix ensures that different namespace resources will be created on each test run, meaning a test run won't be impacted by slow deletion of namespaces from previous runs.

func (*ClusterFixture) PrintDiagnostics

func (fixture *ClusterFixture) PrintDiagnostics()

PrintDiagnostics logs information to stdout that might be helpful for diagnosing test failures (particularly helpful in a CI environment where it is not possible to break execution with a debugger).

type FakeFileSystem

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

FakeFileSystem can be used to test code that uses the FileSystemAccessor interface to access the file system.

func NewFakeFileSystem

func NewFakeFileSystem(lookup map[string]string) *FakeFileSystem

NewFakeFileSystem creates a FileSystemAccessor based on a map where the keys represent file paths and the values represent file content.

func (*FakeFileSystem) AddOrUpdateFile

func (ffs *FakeFileSystem) AddOrUpdateFile(path, content string)

func (*FakeFileSystem) DeleteFile

func (ffs *FakeFileSystem) DeleteFile(path string)

func (*FakeFileSystem) FileExists

func (ffs *FakeFileSystem) FileExists(path string) (bool, error)

FileExists implements the FileSystemAccessor interface

func (*FakeFileSystem) GetFileReader

func (ffs *FakeFileSystem) GetFileReader(path string) (io.ReadCloser, error)

GetFileReader implements the FileSystemAccessor interface

func (*FakeFileSystem) GetFileSize

func (ffs *FakeFileSystem) GetFileSize(path string) (int64, error)

GetFileSize implements the FileSystemAccessor interface

func (*FakeFileSystem) ListFiles

func (ffs *FakeFileSystem) ListFiles(directoryPath string) ([]string, error)

ListFiles implements the FileSystemAccessor interface

func (*FakeFileSystem) SetFileAccessError

func (ffs *FakeFileSystem) SetFileAccessError(path string, err error)

type KnownNamespaces

type KnownNamespaces struct {
	OsmSystem        string
	OsmBookBuyer     string
	OsmBookStore     string
	OsmBookThief     string
	OsmBookWarehouse string
	Periscope        string
}

type ToolsCommandRunner

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

ToolsCommandRunner provides a means to invoke command-line tools within a Docker container made for testing purposes.

func NewToolsCommandRunner

func NewToolsCommandRunner(client *client.Client) *ToolsCommandRunner

func (*ToolsCommandRunner) Run

func (creator *ToolsCommandRunner) Run(command string, volumeBinds ...string) (string, error)

Run executest the specified command in the tools container, with the specified volume bindings. It returns the stdout of the executed command.

type ToolsImageBuilder

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

ToolsImageBuilder provides a method for building the Docker image that contains all the tools involved in initializing a Kind cluster for tests.

func NewToolsImageBuilder

func NewToolsImageBuilder(client *client.Client) *ToolsImageBuilder

func (*ToolsImageBuilder) Build

func (builder *ToolsImageBuilder) Build() error

Jump to

Keyboard shortcuts

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