clean_like_gopher

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

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

Go to latest
Published: Feb 12, 2017 License: GPL-3.0 Imports: 9 Imported by: 0

README

Clean like gopher

Clean like gopher is inspired from database_cleaner. The purpose of clean like gopher is to ensure that the DB is clean between tests.

GoDoc

TODO:

  • Add transaction for mysql
  • Implement redis cleaner
  • Use ginkgo for test
  • Write better tests for different strategies

Supported drivers

Install:

  go get "github.com/tborisova/clean_like_gopher"

Usage

  import 'github.com/tborisova/clean_like_gopher'
  ...
  
  options := map[string]string{"host": "localhost", "dbName": "test", "port": "27017"}
  m := clean_like_gopher.NewCleaningGopher("mongo", options) // clean collection 'test' using mongo driver and truncation strategy
  ...
  dirty db
  ...
  options = map[string]string{"strategy": "truncation"}
  m.Clean(options) // clean all tables with truncation
  m.Close() // after all specs or after each spec

Examples:

Availabe strategies:

  • For mysql/postgres:
    • truncation(default), deletion, transaction (in future development)
  • For mongo:
    • truncation - default
  • For redis:
    • truncation - default

When using 'transaction' strategy you need to call Start() before the tests because it needs to know to open up a transaction.

Available options for truncation strategies:

  • except: ["people", "animals"] - deletes all tables except 'people' and 'animals'
  • only: ['people', 'animals'] - deletes only 'people' and 'animals' tables

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnsupportedDriver = errors.New("Unsupported database driver.")

Functions

func CollectionCanBeDeleted

func CollectionCanBeDeleted(name string, options map[string][]string) bool

checks if collection can be deleted by selected options

func SelectStrategy

func SelectStrategy(options map[string][]string) string

returns specified strategy

Types

type Generic

type Generic interface {
	Clean(options map[string][]string)
	Close()
}

func NewCleaningGopher

func NewCleaningGopher(adapter string, options map[string]string) (Generic, error)

Creates new Cleaner based on the chosen adapter

type GopherError

type GopherError struct {
	Message string
}

func (*GopherError) Error

func (e *GopherError) Error() string

type Mongo

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

Mongo type fields:

name - contains the DB name
session - new connection to the db

func NewMongoCleaningGopher

func NewMongoCleaningGopher(options map[string]string) (*Mongo, error)

creates new cleaner for mongo driver

func (*Mongo) Clean

func (m *Mongo) Clean(options map[string][]string)

Clean with Mongo adapter

func (*Mongo) CleanWithTruncation

func (m *Mongo) CleanWithTruncation()

Clean with Mongo adapter - truncation strategy

func (Mongo) Close

func (m Mongo) Close()

closes the connection to the DB

func (Mongo) String

func (m Mongo) String() string

For debug purposes

type Mysql

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

func NewMysqlConnection

func NewMysqlConnection(options map[string]string) (*Mysql, error)

creates new cleaner for mysql driver

func (*Mysql) DB

func (m *Mysql) DB() *sql.DB

func (*Mysql) TableNames

func (m *Mysql) TableNames() []string

returns all table names

type Postgres

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

func NewPostgresConnection

func NewPostgresConnection(options map[string]string) (*Postgres, error)

creates new cleaner for mysql driver

func (*Postgres) DB

func (p *Postgres) DB() *sql.DB

func (*Postgres) TableNames

func (p *Postgres) TableNames() []string

returns all table names

type Redis

type Redis struct {
	Name    string
	Stategy string
	Options map[string][]string
}

Redis type fields:

name - contains the DB name
strategy - contains the selected strategy for cleaning the DB
options - options for additional info - [except, only]

func NewRedisCleaningGopher

func NewRedisCleaningGopher(options map[string]string) *Redis

func (*Redis) Clean

func (m *Redis) Clean(options map[string][]string)

Clean with Redis adapter

func (*Redis) CleanWithTruncation

func (m *Redis) CleanWithTruncation()

Clean with Redis adapter - truncation strategy

func (*Redis) Close

func (m *Redis) Close()

func (Redis) String

func (m Redis) String() string

For debug purposes

type TruncateableSqlCleaner

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

func NewTruncateableSqlCleaningGopher

func NewTruncateableSqlCleaningGopher(adapter string, options map[string]string) (*TruncateableSqlCleaner, error)

func (*TruncateableSqlCleaner) Clean

func (tsc *TruncateableSqlCleaner) Clean(options map[string][]string)

func (*TruncateableSqlCleaner) CleanWithStatment

func (tsc *TruncateableSqlCleaner) CleanWithStatment(options map[string][]string, stm string) error

func (*TruncateableSqlCleaner) Close

func (tsc *TruncateableSqlCleaner) Close()

closes the connection to the DB

func (*TruncateableSqlCleaner) String

func (tsc *TruncateableSqlCleaner) String() string

For debug purposes

type TruncateableSqlDatabase

type TruncateableSqlDatabase interface {
	TableNames() []string
	DB() *sql.DB
}

Jump to

Keyboard shortcuts

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