assertions

package
v0.11.3-merged-prereqs Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

README

Assertion

If you intend to introduce a new assertion, please follow this approach:

  • We want to avoid writing generic assertions, that are specific to certain tests. Assertions should contain no custom logic, and instead support dependency injection.
  • If you are unsure if an assertion is generic, start by adding it directly to your test, and then you can make it more generic in a follow-up.

Conventions

Contextual Assertions

Some assertions provided in this package may consider the Gloo Gateway context for conditional logic based on metadata about the installation being asserted against. One example is asserting behavior differently if the validating webhook is installed and configured to reject certain resources.

Well Known Manifests

Additionally, some assertions may rely on well-known strings in the manifest filenames for conditional logic. As mentioned above, an example is asserting behavior differently if a manifest is expected to be rejected by the validating webhook.

Documentation

Index

Constants

View Source
const WebhookReject = "webhook-reject"

WebhookReject is a well-known string that should be placed in the filename of any manifest which should be rejected by the Gloo Gateway validating webhook if it is enabled and configured to reject on errors. This acts as signal for any assertion which needs to know if the manifest is expected to not be admitted to the cluster.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	Assert  *assert.Assertions
	Require *require.Assertions

	// Gomega is well-used around the codebase, so we also add support here
	// NOTE TO DEVELOPERS: We recommend relying on testify assertions where possible
	Gomega gomega.Gomega
	// contains filtered or unexported fields
}

Provider is the entity that provides methods which assert behaviors of a Kubernetes Cluster These assertions occur against a running instance of Gloo Gateway, within a Kubernetes Cluster.

func NewProvider

func NewProvider(t *testing.T) *Provider

NewProvider returns a Provider that will provide Assertions that can be executed against an installation of Gloo Gateway

func (*Provider) AssertEnvoyAdminApi

func (p *Provider) AssertEnvoyAdminApi(
	ctx context.Context,
	envoyDeployment metav1.ObjectMeta,
	adminAssertions ...func(ctx context.Context, adminClient *admincli.Client),
)

func (*Provider) AssertEventualCurlResponse

func (p *Provider) AssertEventualCurlResponse(
	ctx context.Context,
	podOpts kubectl.PodExecOptions,
	curlOptions []curl.Option,
	expectedResponse *matchers.HttpResponse,
	timeout ...time.Duration,
)

func (*Provider) AssertEventuallyConsistentCurlResponse

func (p *Provider) AssertEventuallyConsistentCurlResponse(
	ctx context.Context,
	podOpts kubectl.PodExecOptions,
	curlOptions []curl.Option,
	expectedResponse *matchers.HttpResponse,
	timeout ...time.Duration,
)

AssertEventuallyConsistentCurlResponse asserts that the response from a curl command eventually and then consistently matches the expected response

func (*Provider) AssertHTTPRouteStatusContainsReason

func (p *Provider) AssertHTTPRouteStatusContainsReason(route *gwv1.HTTPRoute, reason string)

AssertHTTPRouteStatusContainsSubstring asserts that at least one of the HTTPRoute's route parent statuses contains the given reason substring.

func (*Provider) AssertHTTPRouteStatusContainsSubstring

func (p *Provider) AssertHTTPRouteStatusContainsSubstring(route *gwv1.HTTPRoute, message string)

AssertHTTPRouteStatusContainsSubstring asserts that at least one of the HTTPRoute's route parent statuses contains the given message substring.

func (*Provider) ConsistentlyObjectsNotExist

func (p *Provider) ConsistentlyObjectsNotExist(ctx context.Context, objects ...client.Object)

func (*Provider) EventuallyCheckResourcesOk

func (p *Provider) EventuallyCheckResourcesOk(ctx context.Context)

EventuallyCheckResourcesOk asserts that `glooctl check` eventually responds Ok

func (*Provider) EventuallyInstallationSucceeded

func (p *Provider) EventuallyInstallationSucceeded(ctx context.Context)

func (*Provider) EventuallyObjectsExist

func (p *Provider) EventuallyObjectsExist(ctx context.Context, objects ...client.Object)

func (*Provider) EventuallyObjectsNotExist

func (p *Provider) EventuallyObjectsNotExist(ctx context.Context, objects ...client.Object)

func (*Provider) EventuallyPodsMatches

func (p *Provider) EventuallyPodsMatches(
	ctx context.Context,
	podNamespace string,
	listOpt metav1.ListOptions,
	matcher types.GomegaMatcher,
	timeout ...time.Duration,
)

EventuallyPodsMatches asserts that the pod(s) in the given namespace matches the provided matcher

func (*Provider) EventuallyPodsRunning

func (p *Provider) EventuallyPodsRunning(
	ctx context.Context,
	podNamespace string,
	listOpt metav1.ListOptions,
	timeout ...time.Duration,
)

EventuallyPodsRunning asserts that the pod(s) are in the ready state

func (*Provider) EventuallyResourceStatusMatchesState

func (p *Provider) EventuallyResourceStatusMatchesState(
	getter helpers.InputResourceGetter,
	desiredState core.Status_State,
	desiredReporter string,
	timeout ...time.Duration,
)

func (*Provider) EventuallyResourceStatusMatchesWarningReasons

func (p *Provider) EventuallyResourceStatusMatchesWarningReasons(getter helpers.InputResourceGetter, desiredStatusReasons []string, desiredReporter string, timeout ...time.Duration)

Checks GetNamespacedStatuses status for gloo installation namespace

func (*Provider) EventuallyRunningReplicas

func (p *Provider) EventuallyRunningReplicas(ctx context.Context, deploymentMeta metav1.ObjectMeta, replicaMatcher types.GomegaMatcher)

func (*Provider) EventuallyUninstallationSucceeded

func (p *Provider) EventuallyUninstallationSucceeded(ctx context.Context)

func (*Provider) ExpectGlooObjectNotExist

func (p *Provider) ExpectGlooObjectNotExist(ctx context.Context, getter helpers.InputResourceGetter, meta *metav1.ObjectMeta)

func (*Provider) ExpectNamespaceNotExist

func (p *Provider) ExpectNamespaceNotExist(ctx context.Context, ns string)

func (*Provider) ExpectObjectAdmitted

func (p *Provider) ExpectObjectAdmitted(manifest string, err error, actualOutput, expectedOutput string)

ExpectObjectAdmitted should be used when applying Policy objects that are subject to the Gloo Gateway Validation Webhook If the testInstallation has validation enabled and the manifest contains a known substring (e.g. `webhook-reject`) we expect the application to fail, with an expected error substring supplied as `expectedOutput`

func (*Provider) ExpectObjectDeleted

func (p *Provider) ExpectObjectDeleted(manifest string, err error, actualOutput string)

func (*Provider) WithClusterContext

func (p *Provider) WithClusterContext(clusterContext *cluster.Context) *Provider

WithClusterContext sets the provider to point to the provided cluster

func (*Provider) WithGlooGatewayContext

func (p *Provider) WithGlooGatewayContext(ggCtx *gloogateway.Context) *Provider

WithGlooGatewayContext sets the providers to point to a particular installation of Gloo Gateway

Jump to

Keyboard shortcuts

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