All Projects → khaiql → Dbcleaner

khaiql / Dbcleaner

Licence: mit
Clean database for testing, inspired by database_cleaner for Ruby

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Dbcleaner

kmtest
Kernel-mode C++ unit testing framework in BDD-style
Stars: ✭ 42 (-66.4%)
Mutual labels:  unit-testing, driver
Libfprint
libfrpint driver for a family of Elantech fingerprint sensors
Stars: ✭ 121 (-3.2%)
Mutual labels:  driver
Test
The reference C++ unit testing framework (TDD, xUnit, C++03/11/14/17)
Stars: ✭ 112 (-10.4%)
Mutual labels:  unit-testing
Movieapp
🎬 MovieApp is a Flutter application built to demonstrate the use of modern development tools with best practices implementation like Modularization, BLoC, Dependency Injection, Dynamic Theme, Cache, Shimmer, Testing, Flavor, CI/CD, etc.
Stars: ✭ 117 (-6.4%)
Mutual labels:  unit-testing
Go Hdb
SAP HANA Database Client for Go
Stars: ✭ 113 (-9.6%)
Mutual labels:  driver
Stryker4s
Mutation testing for Scala. Work in progress...
Stars: ✭ 118 (-5.6%)
Mutual labels:  unit-testing
Tl Wn722n V2
Drivers for TP-LINK TL-WN722N version 2 .Clean ported for kernel 4.4, 4.8, 4.10 ,4.13 ,4.14 & 4.15 from source which was at 4.3
Stars: ✭ 112 (-10.4%)
Mutual labels:  driver
Pgsql
Erlang PostgreSQL driver
Stars: ✭ 123 (-1.6%)
Mutual labels:  driver
Deequ
Deequ is a library built on top of Apache Spark for defining "unit tests for data", which measure data quality in large datasets.
Stars: ✭ 2,020 (+1516%)
Mutual labels:  unit-testing
Mettle
A C++17 unit test framework
Stars: ✭ 116 (-7.2%)
Mutual labels:  unit-testing
Fakery
👽 Swift fake data generator
Stars: ✭ 1,572 (+1157.6%)
Mutual labels:  unit-testing
Hulaaki
DEPRECATED : An Elixir library (driver) for clients communicating with MQTT brokers(via the MQTT 3.1.1 protocol).
Stars: ✭ 115 (-8%)
Mutual labels:  driver
Test Smells
Test Smells for Android developers
Stars: ✭ 120 (-4%)
Mutual labels:  unit-testing
Wfpstarterkit
An example driver for Windows that shows how to set-up some basic components of the Windows Filtering Platform
Stars: ✭ 113 (-9.6%)
Mutual labels:  driver
Libneo4j Client
neo4j-client -- Neo4j Command Line Interface (CLI)
Stars: ✭ 121 (-3.2%)
Mutual labels:  driver
Sms
Laravel SMS Gateway Integration Package
Stars: ✭ 112 (-10.4%)
Mutual labels:  driver
Sequelize Mock
A simple mock interface specifically for testing code relying on Sequelize models
Stars: ✭ 116 (-7.2%)
Mutual labels:  unit-testing
Rdfunit
An RDF Unit Testing Suite
Stars: ✭ 117 (-6.4%)
Mutual labels:  unit-testing
Rethinkdb Go
Go language driver for RethinkDB
Stars: ✭ 1,582 (+1165.6%)
Mutual labels:  driver
Esp32 Arduino Can
An Arduino CAN-Bus library for ESP32
Stars: ✭ 121 (-3.2%)
Mutual labels:  driver

DbCleaner

Build Status GoDoc Go Report Card

Clean database for testing, inspired by database_cleaner for Ruby. It uses flock syscall under the hood to make sure the test can runs in parallel without racing issues.

Basic usage

  • To get the package, execute:
go get gopkg.in/khaiql/dbcleaner.v2
  • To import this package, add the following line to your code:
import "gopkg.in/khaiql/dbcleaner.v2"
  • To install TestSuite:
go get github.com/stretchr/testify
  • For people who is using old version (v1.0), please change your import to
import "gopkg.in/khaiql/dbcleaner.v1"

Options

During running test suites, there might be deadlock when 2 suites try to acquire the same table. Dbcleaner tries to mitigate the issue by providing options for retry and panic when the deadlock couldn't be resolved after excessive retries.

type Options struct {
	Logger        logging.Logger
	LockTimeout   time.Duration
	NumberOfRetry int
	RetryInterval time.Duration
}

type Option func(opt *Options)

// SetLogger to an instance of logging.Logger, default to Noop
func SetLogger(logger logging.Logger) Option {
	return func(opt *Options) {
		opt.Logger = logger
	}
}

// SetLockTimeout sets timeout for locking operation, default to 10 seconds
func SetLockTimeout(d time.Duration) Option {
	return func(opt *Options) {
		opt.LockTimeout = d
	}
}

// SetNumberOfRetry sets max retries for acquire the table, default to 5 times
func SetNumberOfRetry(t int) Option {
	return func(opt *Options) {
		opt.NumberOfRetry = t
	}
}

// SetRetryInterval sets sleep duration between each retry, default to 10 seconds
func SetRetryInterval(d time.Duration) Option {
	return func(opt *Options) {
		opt.RetryInterval = d
	}
}

// SetLockFileDir sets directory for lock files
func SetLockFileDir(dir string) Option {
	return func(opt *Options) {
		opt.LockFileDir = dir
	}
}

cleaner := dbcleaner.New(SetNumberOfRetry(10), SetLockTimeout(5*time.Second))

Using with testify's suite

import (
	"testing"

  	"gopkg.in/khaiql/dbcleaner.v2"
  	"gopkg.in/khaiql/dbcleaner.v2/engine"
	"github.com/stretchr/testify/suite"
)

var Cleaner = dbcleaner.New()

type ExampleSuite struct {
	suite.Suite
}

func (suite *ExampleSuite) SetupSuite() {
  	// Init and set mysql cleanup engine
  	mysql := engine.NewMySQLEngine("YOUR_DB_DSN")
  	Cleaner.SetEngine(mysql)
}

func (suite *ExampleSuite) SetupTest() {
  	Cleaner.Acquire("users")
}

func (suite *ExampleSuite) TearDownTest() {
  	Cleaner.Clean("users")
}

func (suite *ExampleSuite) TestSomething() {
  	// Have some meaningful test
  	suite.Equal(true, true)
}

func TestRunSuite(t *testing.T) {
  	suite.Run(t, new(ExampleSuite))
}

Support drivers

  • postgres
  • mysql
  • sqlite3

Write cleaner for other drivers

Basically all drivers supported by database/sql package are also supported by dbcleaner. Check list of drivers: https://github.com/golang/go/wiki/SQLDrivers

For custom driver, implement your own engine.Engine interface and call SetEngine on dbcleaner.Cleaner instance.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].