ts

package module
v0.0.0-...-0b85be9 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2015 License: MIT Imports: 12 Imported by: 0

README

ts (teststore)

Circle CI GoDoc

ts (teststore) is a small Go library that uses Docker to simplify launching temporary database/cache/storage servers for testing purposes.

IMPORTANT NOTE: ts is a work-in-progress and should be treated as such. Please file issues where appropriate.

ts works with both local docker installs and with boot2docker. Usage from inside a container is not yet supported, but should be possible so long as the container has the right privileges.

Supported Backends

Example Usage

Each of teststore's backends implement the same simple API. For example, a simple test that uses the Redis backend with the redigo library might look like:

func TestRedis(t *testing.T) {
	store, err := ts.NewRedis()
	if err != nil {
		t.Error(err.Error())
		return
	}
	defer store.Shutdown()

	u := store.URL()
	conn, err := redis.Dial(u.Scheme, u.Host)
	if err != nil {
		t.Error(err.Error())
		return
	}
	defer conn.Close()

	// set an integer value in redis and read it back
	conn.Do("SET", "k1", 1)
	n, err := redis.Int(conn.Do("GET", "k1"))
	if err != nil {
		t.Error(err.Error())
		return
	}

	if n != 1 {
		t.Error(fmt.Errorf("Redis error: Expected 1, got %d", n))
		return
	}
}

See GoDoc for full library documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InfluxDB

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

InfluxDB implements the Store interface, representing a running InfluxDB instance inside a Docker container.

func (*InfluxDB) Shutdown

func (i *InfluxDB) Shutdown() error

Shutdown stops the InfluxDB instance and destroys the Docker container in which it was running

func (*InfluxDB) URL

func (i *InfluxDB) URL() *url.URL

URL returns a url.URL instance that can be used to interact with the newly started InfluxDB instance

type Postgres

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

Postgres implements the Store interface, representing a running PostgreSQL instance.

func (*Postgres) Shutdown

func (p *Postgres) Shutdown() error

Shutdown stops the PostgreSQL instance and destroys the Docker container in which it was running

func (*Postgres) URL

func (p *Postgres) URL() *url.URL

URL returns a url.URL instance that can be used to interact with the newly started PostgreSQL instance

type Redis

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

Redis implements the Store interface, representing a running Redis instance.

func (*Redis) Shutdown

func (r *Redis) Shutdown() error

Shutdown stops the Redis instance and destroys the Docker container in which it was running

func (*Redis) URL

func (r *Redis) URL() *url.URL

URL returns a url.URL instance that can be used to interact with the newly started Redis instance

type Store

type Store interface {
	URL() *url.URL
	Shutdown() error
}

Store is the common interface implemented by all provided storage backends

func NewInfluxDB

func NewInfluxDB() (Store, error)

NewInfluxDB starts a temporary InfluxDB instance using Docker, returning an InfluxDB struct which contains the required information for clients to interact with the server.

func NewPostgres

func NewPostgres() (Store, error)

NewPostgres starts a temporary PostgreSQL instance using Docker, returning a Postgres struct which contains the required information for clients to interact with the running server.

func NewRedis

func NewRedis() (Store, error)

NewRedis starts a temporary Redis instance using Docker, returning a Redis struct which contains the required information for clients to interact with the server.

Jump to

Keyboard shortcuts

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