drivertest

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package drivertest provides a conformance test for implementations of driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunBenchmarks

func RunBenchmarks(b *testing.B, topic *pubsub.Topic, sub *pubsub.Subscription)

RunBenchmarks runs benchmarks for driver implementations of pubsub.

func RunConformanceTests

func RunConformanceTests(t *testing.T, newHarness HarnessMaker, asTests []AsTest)

RunConformanceTests runs conformance tests for driver implementations of pubsub.

Types

type AsTest

type AsTest interface {
	// Name should return a descriptive name for the test.
	Name() string
	// TopicCheck will be called to allow verifcation of Topic.As.
	TopicCheck(t *pubsub.Topic) error
	// SubscriptionCheck will be called to allow verification of Subscription.As.
	SubscriptionCheck(s *pubsub.Subscription) error
	// TopicErrorCheck will be called to allow verification of Topic.ErrorAs.
	// The error will be the one returned from SendBatch when called with
	// a non-existent topic.
	TopicErrorCheck(t *pubsub.Topic, err error) error
	// SubscriptionErrorCheck will be called to allow verification of
	// Subscription.ErrorAs.
	// The error will be the one returned from ReceiveBatch when called with
	// a non-existent subscription.
	SubscriptionErrorCheck(s *pubsub.Subscription, err error) error
	// MessageCheck will be called to allow verification of Message.As.
	MessageCheck(m *pubsub.Message) error
	// BeforeSend will be used as Message.BeforeSend as part of sending a test
	// message.
	BeforeSend(as func(interface{}) bool) error
	// AfterSend will be used as Message.AfterSend as part of sending a test
	// message.
	AfterSend(as func(interface{}) bool) error
}

AsTest represents a test of As functionality. The conformance test:

  1. Calls TopicCheck.
  2. Calls SubscriptionCheck.
  3. Sends a message, setting Message.BeforeSend to BeforeSend and Message.AfterSend to AfterSend.
  4. Receives the message and calls MessageCheck.
  5. Calls TopicErrorCheck.
  6. Calls SubscriptionErrorCheck.

type Harness

type Harness interface {
	// CreateTopic creates a new topic and returns a driver.Topic
	// for testing. The topic may have to be removed manually if the test is
	// abruptly terminated or the network connection fails.
	CreateTopic(ctx context.Context, testName string) (dt driver.Topic, cleanup func(), err error)

	// MakeNonexistentTopic makes a driver.Topic referencing a topic that
	// does not exist.
	MakeNonexistentTopic(ctx context.Context) (driver.Topic, error)

	// CreateSubscription creates a new subscription, subscribed
	// to the given topic, and returns a driver.Subscription for testing. The
	// subscription may have to be cleaned up manually if the test is abruptly
	// terminated or the network connection fails.
	CreateSubscription(ctx context.Context, t driver.Topic, testName string) (ds driver.Subscription, cleanup func(), err error)

	// MakeNonexistentSubscription makes a driver.Subscription referencing a
	// subscription that does not exist.
	MakeNonexistentSubscription(ctx context.Context) (ds driver.Subscription, cleanup func(), err error)

	// Close closes resources used by the harness, but does not call Close
	// on the Topics and Subscriptions generated by the Harness.
	Close()

	// MaxBatchSizes returns the maximum size of SendBatch/Send(Na|A)cks, or 0
	// if there's no max.
	MaxBatchSizes() (int, int)

	// SupportsMultipleSubscriptions reports whether the driver supports
	// multiple subscriptions for the same topic.
	SupportsMultipleSubscriptions() bool
}

Harness descibes the functionality test harnesses must provide to run conformance tests.

type HarnessMaker

type HarnessMaker func(ctx context.Context, t *testing.T) (Harness, error)

HarnessMaker describes functions that construct a harness for running tests. It is called exactly once per test; Harness.Close() will be called when the test is complete.

Jump to

Keyboard shortcuts

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