Giter Club home page Giter Club logo

gofixtures's Introduction

gofixtures

Ruby on Rails' style test fixtures for Golang, use database transation to keep database clean state

Getting started

Install the package by:

go get -u github.com/Martin91/gofixtures

Example

  1. Reference to dummy to see demo yaml files.
  2. In your project, initalize database connection like:
    import (
        _ "github.com/go-sql-driver/mysql"
        "github.com/Martin91/gofixtures"
    )
    
    // fixtures is shipped with a builtin sql driver which supports rollback db automatically,
    //  so it is required to setup a transational *sql.DB by fixtures
    db := fixtures.OpenDB("mysql", "root:@tcp(localhost:3306)/?charset=utf8&parseTime=True&loc=Local")
    fixtures := fixtures.Load(tt.args.path, db)
    
    // do your test and something else
    
    // once the program exit, fixtures will rollback all database changes automatically
    
    // or if you want to manually rollback, run
    db.Driver().(base.TxDriverIface).ManualRollback()

NOTICE

This repository is still under active development and the overall design and performance is unstable.

Features (WIP, please keep looking forward to it)

[x] YAML based simple and clean syntax
[x] Built-in Faker supported
[x] Bundled field evaluators, enable you to customize dynamic data generation
[x] Support specifying database and tables
[x] Based on standard sql package, compatible with different dialects
[x] Transaction based database cleaner
[ ] Templates to support batch data

TODOs

  1. Test with different databases
  2. Complete test cases with high test coverage
  3. Review the overall architecture design

gofixtures's People

Contributors

martin91 avatar

Stargazers

nlimpid avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.