gocbt

package module
v0.0.0-...-479af4e Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Couchbase integration testing in Go

gocbt is a package to help you write integration tests with Couchbase. If your Go project uses Couchbase and you want to write integration tests for it, gocbt can simplify the setup and teardown of nodes.

By default gocbt pulls the official Couchbase Docker image, but can be configured to pull any image from any repository. Configuration of the nodes is completely customizable, but sensible defaults are used so only the settings important to your particular use case need be defined.

Below is a simple demonstration of how gocbt is used with default configuration. Read about what configuration options are available here.

func TestUserRegistration(t *testing.T) {
    node := gocbt.NewNode()
    defer node.Teardown(t)
    node.Setup(t)
    node.Configure(t, gocbt.Bucket("users"))

    // Connect to Couchbase
    app := StartApp(Config{
        CouchbaseHost:     node.Host(),
        CouchbaseUsername: node.Username(),
        CouchbasePassword: node.Password(),
    })

    // Run the test case
    err := RegisterUser("John", "Doe", "john.doe@domain.com")
    if err != nil {
        t.Fatal("failed to register user")
    }
}

gocbt currently only targets Couchbase Server 6.0.0 Community; other versions may work but have not been tested.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketConfigOption

type BucketConfigOption func(*bucketConfig)

BucketConfigOption functions can be passed to Bucket() to configure its creation.

func MemoryQuota

func MemoryQuota(mb int) BucketConfigOption

MemoryQuota for a bucket in megabytes.

type Cluster

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

Cluster provides access to cluster-level configuration and operations.

type ClusterConfigOption

type ClusterConfigOption func(*clusterConfig)

ClusterConfigOption functions can be passed to Node.Configure() to configure its creation.

func Bucket

func Bucket(name string, opts ...BucketConfigOption) ClusterConfigOption

Bucket configures a bucket creation with the specified name, and other optional parameters.

func BucketTimeout

func BucketTimeout(secs int) ClusterConfigOption

BucketTimeout configures a time in seconds to wait for a bucket to be created.

func GeoSearchIndex

func GeoSearchIndex(name, bucket string) ClusterConfigOption

GeoSearchIndex configures a geospatial index creation with the specified name for the specified bucket.

func IndexTimeout

func IndexTimeout(secs int) ClusterConfigOption

IndexTimeout configures a time in seconds to wait for an index to be created.

type Node

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

Node provides access to node-level configuration and operations.

func NewNode

func NewNode() *Node

NewNode creates a new Node struct.

func (*Node) Configure

func (n *Node) Configure(t *testing.T, opts ...ClusterConfigOption)

Configure buckets and indexes.

func (*Node) Host

func (n *Node) Host() string

Host returns connection string that can be used with gocb.Connect().

func (*Node) Password

func (n *Node) Password() string

Password of the node.

func (*Node) Setup

func (n *Node) Setup(t *testing.T, opts ...NodeConfigOption) *Node

Setup creates a new Couchbase node with optional specified configuration. Configuration includes the Docker image to use, node memory quotas, and node credentials.

func (*Node) Teardown

func (n *Node) Teardown(t *testing.T)

Teardown the node destroys the container.

func (*Node) Username

func (n *Node) Username() string

Username of the node.

type NodeConfigOption

type NodeConfigOption func(*nodeConfig)

NodeConfigOption functions can be passed to Node.Setup() to configure its creation.

func AlwaysPull

func AlwaysPull(pull bool) NodeConfigOption

AlwaysPull is set to true by default. When true, Node.Setup() will attempt to pull the latest image specified by DockerImage(). When false, Node.Setup() will use the locally available image specified by DockerImage(). Setting this to true allows the library to be used without a network connection.

func Credentials

func Credentials(username, password string) NodeConfigOption

Credentials configures the username and password for the node. These can be retrieved again with Node.Username() and Node.Password().

func DockerImage

func DockerImage(image string) NodeConfigOption

DockerImage configures the Couchbase image.

func MemoryQuotas

func MemoryQuotas(dataMb, indexMb, searchMb uint) NodeConfigOption

MemoryQuotas configures the data, index and search memory quotas in megabytes.

func Port

func Port(port uint) NodeConfigOption

Port configures the port.

func Timeout

func Timeout(secs int) NodeConfigOption

Timeout configures a time in seconds to wait for a node to be available.

Jump to

Keyboard shortcuts

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