lib

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: Apache-2.0 Imports: 68 Imported by: 0

Documentation

Overview

Utility functions used for testing

Index

Constants

View Source
const (
	PubSubServiceName           = "pubsub.googleapis.com"
	PubSubCreateTopicMethodName = "google.pubsub.v1.Publisher.CreateTopic"
)
View Source
const (
	ProwProjectKey = "E2E_PROJECT_ID"

	EventCountMetricType     = "custom.googleapis.com/cloud.google.com/source/event_count"
	GlobalMetricResourceType = "global"
	StorageResourceGroup     = "storages.events.cloud.google.com"
	PubsubResourceGroup      = "pubsubs.events.cloud.google.com"

	BrokerEventCountMetricType = "knative.dev/eventing/broker/event_count"
	BrokerMetricResourceType   = "knative_broker"

	TriggerEventCountMetricType       = "knative.dev/eventing/trigger/event_count"
	TriggerEventDispatchLatencyType   = "knative.dev/eventing/trigger/event_dispatch_latencies"
	TriggerEventProcessingLatencyType = "knative.dev/eventing/trigger/event_processing_latencies"
	TriggerMonitoredResourceType      = "knative_trigger"

	EventType          = "type"
	EventSource        = "source"
	EventDataSchema    = "dataschema"
	EventSubject       = "subject"
	EventSubjectPrefix = "subject-prefix"
	EventID            = "id"
	EventData          = "data"

	E2ERespEventIDPrefix    = "e2e-testing-resp-event-id"
	E2EPubSubRespEventID    = E2ERespEventIDPrefix + "-pubsub"
	E2EBuildRespEventID     = E2ERespEventIDPrefix + "-build"
	E2EStorageRespEventID   = E2ERespEventIDPrefix + "-storage"
	E2EAuditLogsRespEventID = E2ERespEventIDPrefix + "-auditlogs"
	E2ESchedulerRespEventID = E2ERespEventIDPrefix + "-scheduler"
	E2ESampleRespEventID    = E2ERespEventIDPrefix + "-sample"

	E2ERespEventTypePrefix  = "e2e-testing-resp-event-type"
	E2EPubSubRespEventType  = E2ERespEventTypePrefix + "-pubsub"
	E2EBuildRespEventType   = E2ERespEventTypePrefix + "-build"
	E2EStorageRespEventType = E2ERespEventTypePrefix + "-storage"
	E2EAuditLogsRespType    = E2ERespEventTypePrefix + "-auditlogs"
	E2ESchedulerRespType    = E2ERespEventTypePrefix + "-scheduler"
	E2ESampleRespEventType  = E2ERespEventTypePrefix + "-sample"

	// Used in ../test_images/sender, ../test_images/receiver and ../test_images/receiver
	// E2ESampleEventID is the id of the event sent by image `sender`
	E2ESampleEventID = "e2e-sample-event-id"
	// E2ESampleEventType is the type of the event sent by image `sender`
	E2ESampleEventType = "e2e-sample-event-type"
	// E2ESampleEventSource is the source of the event sent by image `sender`
	E2ESampleEventSource = "e2e-sample-event-source"
	// E2ESampleRespEventSource is the source of the resp event sent by image `receiver`
	E2ESampleRespEventSource = "e2e-sample-resp-event-source"
)

Variables

View Source
var BrokerGVK = metav1.GroupVersionKind{
	Group:   "eventing.knative.dev",
	Version: "v1",
	Kind:    "Broker"}
View Source
var BrokerTypeMeta = eventingTypeMeta(eventingresources.BrokerKind)
View Source
var ChannelTypeMeta = messagingTypeMeta(resources.ChannelKind)
View Source
var CloudAuditLogsSourceV1TypeMeta = eventsV1TypeMeta(resources.CloudAuditLogsSourceKind)
View Source
var CloudAuditLogsSourceV1alpha1TypeMeta = eventsV1alpha1TypeMeta(resources.CloudAuditLogsSourceKind)
View Source
var CloudAuditLogsSourceV1beta1TypeMeta = eventsV1beta1TypeMeta(resources.CloudAuditLogsSourceKind)
View Source
var CloudBuildSourceV1TypeMeta = eventsV1TypeMeta(resources.CloudBuildSourceKind)
View Source
var CloudBuildSourceV1alpha1TypeMeta = eventsV1alpha1TypeMeta(resources.CloudBuildSourceKind)
View Source
var CloudBuildSourceV1beta1TypeMeta = eventsV1beta1TypeMeta(resources.CloudBuildSourceKind)
View Source
var CloudPubSubSourceV1TypeMeta = eventsV1TypeMeta(resources.CloudPubSubSourceKind)
View Source
var CloudPubSubSourceV1alpha1TypeMeta = eventsV1alpha1TypeMeta(resources.CloudPubSubSourceKind)
View Source
var CloudPubSubSourceV1beta1TypeMeta = eventsV1beta1TypeMeta(resources.CloudPubSubSourceKind)
View Source
var CloudSchedulerSourceV1TypeMeta = eventsV1TypeMeta(resources.CloudSchedulerSourceKind)
View Source
var CloudSchedulerSourceV1alpha1TypeMeta = eventsV1alpha1TypeMeta(resources.CloudSchedulerSourceKind)
View Source
var CloudSchedulerSourceV1beta1TypeMeta = eventsV1beta1TypeMeta(resources.CloudSchedulerSourceKind)
View Source
var CloudStorageSourceV1TypeMeta = eventsV1TypeMeta(resources.CloudStorageSourceKind)
View Source
var CloudStorageSourceV1alpha1TypeMeta = eventsV1alpha1TypeMeta(resources.CloudStorageSourceKind)
View Source
var CloudStorageSourceV1beta1TypeMeta = eventsV1beta1TypeMeta(resources.CloudStorageSourceKind)
View Source
var JobTypeMeta = batchTypeMeta(resources.JobKind)
View Source
var KsvcTypeMeta = servingTypeMeta(resources.KServiceKind)
View Source
var PullSubscriptionV1TypeMeta = inteventsV1TypeMeta(resources.PullSubscriptionKind)
View Source
var PullSubscriptionV1alpha1TypeMeta = inteventsV1alpha1TypeMeta(resources.PullSubscriptionKind)
View Source
var PullSubscriptionV1beta1TypeMeta = inteventsV1beta1TypeMeta(resources.PullSubscriptionKind)
View Source
var ServiceGVK = metav1.GroupVersionKind{
	Version: "v1",
	Kind:    "Service"}
View Source
var TriggerTypeMeta = eventingTypeMeta(eventingresources.TriggerKind)

Functions

func AddRandomFile

func AddRandomFile(ctx context.Context, t *testing.T, bucketName, fileName, project string)

func AssertMetrics

func AssertMetrics(t *testing.T, client *Client, topicName, psName string)

func BuildWithConfigFile

func BuildWithConfigFile(t *testing.T, imageName string) string

func CloudBuildImage

func CloudBuildImage(project, imageName string) string

func DeleteBucket

func DeleteBucket(ctx context.Context, t *testing.T, bucketName string)

func DeleteTopicOrDie

func DeleteTopicOrDie(t *testing.T, topicName string)

func DuplicatePubSubSecret

func DuplicatePubSubSecret(ctx context.Context, client *eventingtestlib.Client)

DuplicatePubSubSecret duplicates the PubSub secret to the test namespace.

func GetCredential

func GetCredential(ctx context.Context, client *eventingtestlib.Client, workloadIdentity bool)

func GetEnvOrFail

func GetEnvOrFail(t *testing.T, key string) string

GetEnvOrFail gets the specified environment variable. If the variable is not set, then the test exits with an error.

func GetTopic

func GetTopic(t *testing.T, topicName string) *pubsub.Topic

func MakeAuditLogsJobOrDie

func MakeAuditLogsJobOrDie(client *Client, methodName, project, resourceName, serviceName, targetName, eventType string)

func MakeAuditLogsOrDie

func MakeAuditLogsOrDie(client *Client, config AuditLogsConfig)

func MakeAuditLogsV1beta1OrDie

func MakeAuditLogsV1beta1OrDie(client *Client, config AuditLogsConfig)

func MakeBucket

func MakeBucket(ctx context.Context, t *testing.T, project string) string

MakeBucket retrieves the bucket name for the test. If it does not exist, it will create it.

func MakeBuildOrDie

func MakeBuildOrDie(client *Client, config BuildConfig)

func MakeBuildTargetJobOrDie

func MakeBuildTargetJobOrDie(client *Client, images, targetName, eventType string)

func MakeBuildV1beta1OrDie

func MakeBuildV1beta1OrDie(client *Client, config BuildConfig)

func MakePubSub added in v0.21.0

func MakePubSub(client *Client, config PubSubConfig)

func MakePubSubOrDie

func MakePubSubOrDie(client *Client, config PubSubConfig)

func MakePubSubTargetJobOrDie

func MakePubSubTargetJobOrDie(client *Client, source, targetName, eventType string, schema string)

func MakePubSubV1beta1OrDie

func MakePubSubV1beta1OrDie(client *Client, config PubSubConfig)

func MakePullSubscriptionOrDie

func MakePullSubscriptionOrDie(client *Client, config PullSubscriptionConfig)

func MakePullSubscriptionV1beta1OrDie

func MakePullSubscriptionV1beta1OrDie(client *Client, config PullSubscriptionConfig)

func MakeSchedulerJobOrDie

func MakeSchedulerJobOrDie(client *Client, data, targetName, eventType string)

func MakeSchedulerOrDie

func MakeSchedulerOrDie(client *Client, config SchedulerConfig)

func MakeSchedulerV1beta1OrDie

func MakeSchedulerV1beta1OrDie(client *Client, config SchedulerConfig)

func MakeStorageJobOrDie

func MakeStorageJobOrDie(client *Client, source, subject, targetName, eventType string)

func MakeStorageOrDie

func MakeStorageOrDie(client *Client, config StorageConfig)

func MakeStorageV1beta1OrDie

func MakeStorageV1beta1OrDie(client *Client, config StorageConfig)

func MakeTopicOrDie

func MakeTopicOrDie(t *testing.T) (string, func())

func MakeTopicWithNameIfItDoesNotExist

func MakeTopicWithNameIfItDoesNotExist(t *testing.T, topicName string)

func MakeTopicWithNameOrDie

func MakeTopicWithNameOrDie(t *testing.T, topicName string) (string, func())

func NotificationExists

func NotificationExists(t *testing.T, bucketName, notificationID string) bool

func SchedulerJobExists

func SchedulerJobExists(t *testing.T, jobName string) bool

func SetTracingToZipkin

func SetTracingToZipkin(ctx context.Context, client *eventingtestlib.Client)

func StackdriverSinkExists

func StackdriverSinkExists(t *testing.T, sinkID string) bool

func SubscriptionExists

func SubscriptionExists(t *testing.T, subID string) bool

func TearDown

func TearDown(ctx context.Context, client *Client)

TearDown runs the TearDown in the common eventing test framework.

func TopicExists

func TopicExists(t *testing.T, topicID string) bool

func WaitForSourceAuthCheckPending added in v0.21.0

func WaitForSourceAuthCheckPending(dynamicClient dynamic.Interface, obj *resources.MetaResource, wantMessage string) error

WaitForSourceAuthCheckPending polls the status of the Source from client every interval until isSourceAuthCheckPending returns `true` indicating the Source is in AuthenticationCheckPending state and has wanted messages, or returns an error, or timeout. AuthenticationCheckPending is the state that will continue until authentication check succeeds.

func WithServiceForJob

func WithServiceForJob(name string) func(*batchv1.Job, *Client) error

WithServiceForJob returns an option that creates a Service binded with the given job.

Types

type AuditLogsConfig

type AuditLogsConfig struct {
	SinkGVK            metav1.GroupVersionKind
	SinkName           string
	AuditlogsName      string
	MethodName         string
	Project            string
	ResourceName       string
	ServiceName        string
	ServiceAccountName string
}

type AuthConfig

type AuthConfig struct {
	WorkloadIdentity   bool
	ServiceAccountName string
}

type BrokerMetricAssertion

type BrokerMetricAssertion struct {
	ProjectID       string
	BrokerName      string
	BrokerNamespace string
	StartTime       time.Time
	CountPerType    map[string]int64
}

func (BrokerMetricAssertion) Assert

func (BrokerMetricAssertion) StackdriverFilter

func (a BrokerMetricAssertion) StackdriverFilter() string

type BuildConfig

type BuildConfig struct {
	SinkGVK            metav1.GroupVersionKind
	BuildName          string
	SinkName           string
	ServiceAccountName string
}

type Client

type Client struct {
	Core *lib.Client

	KnativeGCP *knativegcp.Clientset
	Namespace  string
	T          *testing.T
	Tracker    *lib.Tracker
}

Client holds instances of interfaces for making requests to Knative.

func Setup

func Setup(ctx context.Context, t *testing.T, runInParallel, workloadIdentity bool) *Client

Setup runs the Setup in the common eventing test framework.

func (*Client) CreateAuditLogsOrFail

func (c *Client) CreateAuditLogsOrFail(auditlogs *eventsv1.CloudAuditLogsSource)

func (*Client) CreateAuditLogsV1beta1OrFail

func (c *Client) CreateAuditLogsV1beta1OrFail(auditlogs *eventsv1beta1.CloudAuditLogsSource)

func (*Client) CreateBuildOrFail

func (c *Client) CreateBuildOrFail(build *eventsv1.CloudBuildSource)

func (*Client) CreateBuildV1beta1OrFail

func (c *Client) CreateBuildV1beta1OrFail(build *eventsv1beta1.CloudBuildSource)

func (*Client) CreateChannelOrFail

func (c *Client) CreateChannelOrFail(channel *messagingv1beta1.Channel)

func (*Client) CreateGCPBrokerOrFail added in v0.22.0

func (c *Client) CreateGCPBrokerOrFail(name string, options ...reconcilertesting.BrokerOption) *brokerv1.Broker

CreateGCPBrokerOrFail will create a GCP Broker or fail the test if there is an error.

func (*Client) CreateJobOrFail

func (c *Client) CreateJobOrFail(job *batchv1.Job, options ...func(*batchv1.Job, *Client) error)

func (*Client) CreatePubSubOrFail

func (c *Client) CreatePubSubOrFail(pubsub *eventsv1.CloudPubSubSource)

func (*Client) CreatePubSubV1beta1OrFail

func (c *Client) CreatePubSubV1beta1OrFail(pubsub *eventsv1beta1.CloudPubSubSource)

func (*Client) CreatePullSubscriptionOrFail

func (c *Client) CreatePullSubscriptionOrFail(pullsubscription *inteventsv1.PullSubscription)

func (*Client) CreatePullSubscriptionV1beta1OrFail

func (c *Client) CreatePullSubscriptionV1beta1OrFail(pullsubscription *inteventsv1beta1.PullSubscription)

func (*Client) CreateSchedulerOrFail

func (c *Client) CreateSchedulerOrFail(scheduler *eventsv1.CloudSchedulerSource)

func (*Client) CreateSchedulerV1beta1OrFail

func (c *Client) CreateSchedulerV1beta1OrFail(scheduler *eventsv1beta1.CloudSchedulerSource)

func (*Client) CreateSecretOrFail added in v0.21.0

func (c *Client) CreateSecretOrFail(secret *corev1.Secret)

func (*Client) CreateServiceAccountOrFail added in v0.21.0

func (c *Client) CreateServiceAccountOrFail(sa *corev1.ServiceAccount)

func (*Client) CreateStorageOrFail

func (c *Client) CreateStorageOrFail(storage *eventsv1.CloudStorageSource)

func (*Client) CreateStorageV1beta1OrFail

func (c *Client) CreateStorageV1beta1OrFail(storage *eventsv1beta1.CloudStorageSource)

func (*Client) CreateTopicOrFail

func (c *Client) CreateTopicOrFail(topic *inteventsv1.Topic)

func (*Client) CreateUnstructuredObjOrFail

func (c *Client) CreateUnstructuredObjOrFail(spec *unstructured.Unstructured)

func (*Client) DeleteAuditLogsOrFail

func (c *Client) DeleteAuditLogsOrFail(name string)

func (*Client) DeleteBuildOrFail

func (c *Client) DeleteBuildOrFail(name string)

func (*Client) DeleteGCPBrokerOrFail

func (c *Client) DeleteGCPBrokerOrFail(name string)

func (*Client) DeletePubSubOrFail

func (c *Client) DeletePubSubOrFail(name string)

func (*Client) DeleteSchedulerOrFail

func (c *Client) DeleteSchedulerOrFail(name string)

func (*Client) DeleteStorageOrFail

func (c *Client) DeleteStorageOrFail(name string)

func (*Client) GetAuditLogsOrFail

func (c *Client) GetAuditLogsOrFail(name string) *eventsv1.CloudAuditLogsSource

func (*Client) GetBuildOrFail

func (c *Client) GetBuildOrFail(name string) *eventsv1.CloudBuildSource

func (*Client) GetPubSubOrFail

func (c *Client) GetPubSubOrFail(name string) *eventsv1.CloudPubSubSource

func (*Client) GetSchedulerOrFail

func (c *Client) GetSchedulerOrFail(name string) *eventsv1.CloudSchedulerSource

func (*Client) GetStorageOrFail

func (c *Client) GetStorageOrFail(name string) *eventsv1.CloudStorageSource

func (*Client) LogsFor

func (c *Client) LogsFor(ctx context.Context, namespace, name string, tm *metav1.TypeMeta) (string, error)

TODO(chizhg): move this function to knative/pkg/test or knative/eventing/test

func (*Client) SetupStackDriverMetrics

func (c *Client) SetupStackDriverMetrics(ctx context.Context, t *testing.T)

func (*Client) SetupStackDriverMetricsInNamespace

func (c *Client) SetupStackDriverMetricsInNamespace(ctx context.Context, t *testing.T)

func (*Client) StackDriverEventCountMetricFor

func (c *Client) StackDriverEventCountMetricFor(_, projectID, filter string) (int64, error)

TODO make this function more generic.

func (*Client) WaitForSourceAuthCheckPendingOrFail added in v0.21.0

func (c *Client) WaitForSourceAuthCheckPendingOrFail(name string, typemeta *metav1.TypeMeta, wantMessage string)

WaitForSourceAuthCheckPendingOrFail waits for the GCP Sources to have authenticationCheckPending condition reason for PullSubscriptionConditionReady condition or fail, and checks if the condition contains wanted message. To use this function, the given resource must have implemented the PubSub Status duck-type, and have PullSubscriptionConditionReady condition.

func (*Client) WaitUntilJobDone

func (c *Client) WaitUntilJobDone(ctx context.Context, namespace, name string) (string, error)

TODO(chizhg): move this function to knative/pkg/test or knative/eventing/test WaitForResourceReady waits until the specified resource in the given namespace are ready.

type Output

type Output interface {
	Successful() bool
}

type PropPair

type PropPair struct {
	Expected string
	Received string
}

type PubSubConfig

type PubSubConfig struct {
	SinkGVK            metav1.GroupVersionKind
	PubSubName         string
	SinkName           string
	TopicName          string
	ServiceAccountName string
}

type PullSubscriptionConfig

type PullSubscriptionConfig struct {
	SinkGVK              metav1.GroupVersionKind
	PullSubscriptionName string
	SinkName             string
	TopicName            string
	ServiceAccountName   string
}

type SchedulerConfig

type SchedulerConfig struct {
	SinkGVK            metav1.GroupVersionKind
	SchedulerName      string
	Data               string
	SinkName           string
	ServiceAccountName string
}

type SenderOutput

type SenderOutput struct {
	TraceID string `json:"traceid"`
	// contains filtered or unexported fields
}

func (*SenderOutput) Successful

func (o *SenderOutput) Successful() bool

type StorageConfig

type StorageConfig struct {
	SinkGVK            metav1.GroupVersionKind
	BucketName         string
	StorageName        string
	SinkName           string
	ServiceAccountName string
	Options            []reconcilertestingv1.CloudStorageSourceOption
}

type TargetOutput

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

func (*TargetOutput) Successful

func (o *TargetOutput) Successful() bool

type TriggerAssertionKey

type TriggerAssertionKey struct {
	Name string
	// If not provided, it means the assertion doesn't care about response code.
	RespCode int
}

type TriggerMetricAssertion

type TriggerMetricAssertion struct {
	ProjectID                   string
	BrokerNamespace             string
	BrokerName                  string
	StartTime                   time.Time
	CountPerTriggerWithRespCode map[TriggerAssertionKey]int64
	CountPerTriggerNoRespCode   map[TriggerAssertionKey]int64
}

func (TriggerMetricAssertion) Assert

func (TriggerMetricAssertion) StackdriverFilter

func (a TriggerMetricAssertion) StackdriverFilter(metric string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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