framework

package
v0.0.0-...-146a38b Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: BSD-3-Clause, Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenRequest represents the "TokenRequest" feature.
	TokenRequest = ClusterFeature("TokenRequest")

	// ShareProcessNamespace represents the "ShareProcessNamespace" feature.
	ShareProcessNamespace = ClusterFeature("ShareProcessNamespace")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterFeature

type ClusterFeature string

ClusterFeature represents a feature that can be enabled or disabled on the target Kubernetes cluster.

type Framework

type Framework struct {
	// ClusterFeatures is a map indicating whether specific
	// cluster features have been detected in the target cluster.
	ClusterFeatures map[ClusterFeature]bool

	// FeatureMap is the map containing features and their status for the current instance of the end-to-end test suite.
	FeatureMap features.FeatureMap

	// KubeClient is an interface to the Kubernetes base APIs.
	KubeClient kubernetes.Interface

	// Namespace is the namespace in which we are running.
	Namespace string

	// NatsClient is an interface to the nats.io/v1alpha2 API.
	NatsClient natsclient.Interface
}

Framework encapsulates the configuration for the current run, and provides helper methods to be used during testing.

func New

func New(featureMap features.FeatureMap, kubeconfig, namespace string) *Framework

New returns a new instance of the testing framework.

func (*Framework) Cleanup

func (f *Framework) Cleanup()

Cleanup deletes the nats-operator deployment and the nats-operator-e2e pod, ignoring errors.

func (*Framework) ConnectToNatsClusterWithNatsServiceRole

func (f *Framework) ConnectToNatsClusterWithNatsServiceRole(natsCluster *natsv1alpha2.NatsCluster, nsr *natsv1alpha2.NatsServiceRole) (*nats.Conn, error)

ConnectToNatsClusterWithNatsServiceRole attempts to connect to the specified NATS cluster using the specified NatsServiceRole. It returns the NATS connection back to the caller, or an error. It is the caller's responsibility to close the connection when it is no longer needed.

func (*Framework) ConnectToNatsClusterWithUsernamePassword

func (f *Framework) ConnectToNatsClusterWithUsernamePassword(natsCluster *natsv1alpha2.NatsCluster, username, password string) (*nats.Conn, error)

ConnectToNatsClusterWithUsernamePassword attempts to connect to the specified NATS cluster using the username and password. It returns the NATS connection back to the caller, or an error. It is the caller's responsibility to close the connection when it is no longer needed.

func (*Framework) CreateCluster

func (f *Framework) CreateCluster(namespace, prefix string, size int, version string, fn ...NatsClusterCustomizer) (*natsv1alpha2.NatsCluster, error)

CreateCluster creates a NatsCluster resource which name starts with the specified prefix, and using the specified size and version.

Before actually creating the NatsCluster resource, it allows for the resource to be customized via the application of NatsClusterCustomizer functions.

func (*Framework) CreateNamespace

func (f *Framework) CreateNamespace() (*corev1.Namespace, error)

CreateNamespace creates a namespace with a random name.

func (*Framework) CreateNatsServiceRole

func (f *Framework) CreateNatsServiceRole(namespace, prefix string, fn ...NatsServiceRoleCustomizer) (*natsv1alpha2.NatsServiceRole, error)

CreateNatsServiceRole creates a NatsServiceRole resource which name starts with the specified prefix. Before actually creating the CreateNatsServiceRole resource, it allows for the resource to be customized via the application of NatsServiceRoleCustomizer functions.

func (*Framework) CreateSecret

func (f *Framework) CreateSecret(namespace string, key string, val []byte) (*v1.Secret, error)

CreateSecret creates a Secret resource containing the specified key and value.

func (*Framework) DeleteCluster

func (f *Framework) DeleteCluster(natsCluster *natsv1alpha2.NatsCluster) error

DeleteCluster deletes the specified NatsCluster resource.

func (*Framework) DeleteNamespace

func (f *Framework) DeleteNamespace(namespace *corev1.Namespace) error

DeleteNamespace deletes the specified namespace.

func (*Framework) DeleteNatsServiceRole

func (f *Framework) DeleteNatsServiceRole(nsr *natsv1alpha2.NatsServiceRole) error

DeleteNatsServiceRole deletes the specified NatsServiceRole resource.

func (*Framework) DeleteSecret

func (f *Framework) DeleteSecret(secret *v1.Secret) error

DeleteSecret deletes the specified Secret resource.

func (*Framework) FeatureDetect

func (f *Framework) FeatureDetect()

FeatureDetect performs feature detection on the target Kubernetes cluster.

func (*Framework) NatsClusterHasExpectedRouteCount

func (f *Framework) NatsClusterHasExpectedRouteCount(natsCluster *natsv1alpha2.NatsCluster, expectedSize int) (bool, error)

NatsClusterHasExpectedRouteCount returns whether every pod in the specified NatsCluster is reporting the expected number of routes.

func (*Framework) NatsClusterHasExpectedVersion

func (f *Framework) NatsClusterHasExpectedVersion(natsCluster *natsv1alpha2.NatsCluster, expectedVersion string) (bool, error)

NatsClusterHasExpectedVersion returns whether every pod in the specified NatsCluster is running the specified version of NATS.

func (*Framework) PatchCluster

func (f *Framework) PatchCluster(natsCluster *natsv1alpha2.NatsCluster) (*natsv1alpha2.NatsCluster, error)

PatchCluster performs a patch on the specified NatsCluster resource to align its ".spec" field with the provided value. It takes the desired state as an argument and patches the NatsCluster resource accordingly.

func (*Framework) PatchNatsServiceRole

func (f *Framework) PatchNatsServiceRole(nsr *natsv1alpha2.NatsServiceRole) (*natsv1alpha2.NatsServiceRole, error)

PatchNatsServiceRole performs a patch on the specified NatsServiceRole resource to align its ".spec" field with the provided value. It takes the desired state as an argument and patches the NatsServiceRole resource accordingly.

func (*Framework) PatchSecret

func (f *Framework) PatchSecret(secret *v1.Secret) (*v1.Secret, error)

PatchSecret performs a patch on the specified Secret resource to align its ".data" field with the provided value. It takes the desired state as an argument and patches the Secret resource accordingly.

func (*Framework) PodsForNatsCluster

func (f *Framework) PodsForNatsCluster(natsCluster *natsv1alpha2.NatsCluster) ([]v1.Pod, error)

PodsForNatsCluster returns a slice containing all pods that belong to the specified NatsCluster resource.

func (*Framework) Require

func (f *Framework) Require(t *testing.T, features ...ClusterFeature)

Require skips a test requiring features that are not enabled in the cluster.

func (*Framework) RouteCountForPod

func (f *Framework) RouteCountForPod(pod v1.Pod) (int, error)

RouteCountForPod returns the number of routes reported by the specified pod.

func (*Framework) SecretsForNatsCluster

func (f *Framework) SecretsForNatsCluster(natsCluster *natsv1alpha2.NatsCluster) ([]v1.Secret, error)

SecretsForNatsCluster returns a slice containing all pods that belong to the specified NatsCluster resource.

func (*Framework) ServicesForNatsCluster

func (f *Framework) ServicesForNatsCluster(natsCluster *natsv1alpha2.NatsCluster) ([]v1.Service, error)

ServicesForNatsCluster returns a slice containing all pods that belong to the specified NatsCluster resource.

func (*Framework) UpdateCluster

func (f *Framework) UpdateCluster(natsCluster *natsv1alpha2.NatsCluster) (*natsv1alpha2.NatsCluster, error)

UpdateCluster deletes the specified NatsCluster resource.

func (*Framework) VersionForPod

func (f *Framework) VersionForPod(pod v1.Pod) (string, error)

VersionForPod returns the version of NATS reported by the specified pod.

func (*Framework) WaitForNatsOperator

func (f *Framework) WaitForNatsOperator() error

WaitForNatsOperator waits for the nats-operator deployment to have at least one available replica.

func (*Framework) WaitForNatsOperatorE2ePodTermination

func (f *Framework) WaitForNatsOperatorE2ePodTermination() (int, error)

WaitForNatsOperatorE2ePodTermination waits for the nats-operator pod to be running and ready. It then starts streaming logs and returns the pod's exit code, or an error if any error was found during the process.

func (*Framework) WaitUntilExpectedRoutesInConfig

func (f *Framework) WaitUntilExpectedRoutesInConfig(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster) error

WaitUntilExpectedRoutesInConfig waits until the expected routes for the specified NatsCluster are present in its configuration secret.

func (*Framework) WaitUntilFullMesh

func (f *Framework) WaitUntilFullMesh(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster, expectedSize int) error

WaitUntilFullMesh waits until all the pods belonging to the specified NatsCluster report the expected number of routes. This function is a weaker variant of WaitUntilFullMeshWithVersion and should only be called in very specific use cases.

func (*Framework) WaitUntilFullMeshWithVersion

func (f *Framework) WaitUntilFullMeshWithVersion(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster, expectedSize int, expectedVersion string) error

WaitUntilFullMeshWithVersion waits until all the pods belonging to the specified NatsCluster report the expected number of routes and the expected version.

func (*Framework) WaitUntilNatsClusterCondition

func (f *Framework) WaitUntilNatsClusterCondition(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster, fn watch.ConditionFunc) error

WaitUntilNatsClusterCondition waits until the specified condition is verified in the specified NatsCluster.

func (*Framework) WaitUntilPodBootContainerLogLineMatches

func (f *Framework) WaitUntilPodBootContainerLogLineMatches(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster, podIndex int, regex string) error

WaitUntilPodBootContainerLogLineMatches waits until a line in the logs for the pod with the specified index and belonging to the specified NatsCluster resource matches the provided regular expression.

func (*Framework) WaitUntilPodLogLineMatches

func (f *Framework) WaitUntilPodLogLineMatches(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster, podIndex int, regex string) error

WaitUntilPodLogLineMatches waits until a line in the logs for the pod with the specified index and belonging to the specified NatsCluster resource matches the provided regular expression.

func (*Framework) WaitUntilSecretCondition

func (f *Framework) WaitUntilSecretCondition(ctx context.Context, natsCluster *natsv1alpha2.NatsCluster, fn watch.ConditionFunc) error

WaitUntilSecretCondition waits until the specified condition is verified in configuration secret for the specified NatsCluster resource.

type NatsClusterCustomizer

type NatsClusterCustomizer func(natsCluster *natsv1alpha2.NatsCluster)

NatsClusterCustomizer represents a function that allows for customizing a NatsCluster resource before it is created.

type NatsServiceRoleCustomizer

type NatsServiceRoleCustomizer func(natsServiceRole *natsv1alpha2.NatsServiceRole)

NatsServiceRoleCustomizer represents a function that allows for customizing a NatsServiceRole resource before it is created.

Jump to

Keyboard shortcuts

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