gocloud.dev: gocloud.dev/pubsub/drivertest Index | Files

package drivertest

import "gocloud.dev/pubsub/drivertest"

Package drivertest provides a conformance test for implementations of driver.

Index

Package Files

drivertest.go

func RunBenchmarks Uses

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

RunBenchmarks runs benchmarks for driver implementations of pubsub.

func RunConformanceTests Uses

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

RunConformanceTests runs conformance tests for driver implementations of pubsub.

type AsTest Uses

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
}

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. 4. Receives the message and calls MessageCheck. 5. Calls TopicErrorCheck. 6. Calls SubscriptionErrorCheck.

type Harness Uses

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) (driver.Subscription, 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 Uses

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.

Package drivertest imports 16 packages (graph). Updated 2020-05-23. Refresh now. Tools for package owners.