redistest

package module
v0.0.0-...-bdb6e55 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 9 Imported by: 0

README

redistest

Go library to spawn single-use Redis servers for unit testing

Build Status Build Status GoDoc

Spawns a Redis server. Ideal for unit tests where you want a clean instance each time. Then clean up afterwards.

Features:

  • Starts a clean isolated Redis database
  • Tested on Fedora, Ubuntu and Alpine
  • Optimized for in-memory execution, to speed up unit tests
  • Less than 0.1 second startup / initialization time

Usage

In your unit test:

red, err := redistest.Start()
defer red.Stop()

// Do something with red.Pool (which is a *redis.Pool)

License

This library is distributed under the MIT license.

Documentation

Overview

Spawns a Redis server. Ideal for unit tests where you want a clean instance each time. Then clean up afterwards.

Requires Redis to be installed on your system (but it doesn't have to be running).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Redis

type Redis struct {

	// A redis pool pre-configured to talk to the redis server
	Pool *redis.Pool

	// Network protocol to pass to redis.Dial()
	Network string

	// Address to pass to redis.Dial()
	Address string
	// contains filtered or unexported fields
}

func Start

func Start() (*Redis, error)

Start a new Redis database, on temporary storage.

This database has persistance disabled for performance, so it might run faster than your production database. This makes it less reliable in case of system crashes, but we don't care about that anyway during unit testing.

Use the Pool field to access the database connection

func (*Redis) Continue

func (s *Redis) Continue()

Resume the server

func (*Redis) Freeze

func (s *Redis) Freeze()

Hang the server, good for testing blocked connections

func (*Redis) Stop

func (s *Redis) Stop() error

Stop the database and remove storage files.

Jump to

Keyboard shortcuts

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