Categorygithub.com/Martin91/gofixtures
modulepackage
0.0.0-20210831035235-cb8210d52554
Repository: https://github.com/martin91/gofixtures.git
Documentation: pkg.go.dev

# README

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

# Packages

No description provided by the author

# Functions

Load parse yaml files under the directory specified by `path`, it may panics if any error encountered.
OpenDB setup a transactional db to automatically rollback db changes, it may panics if any error encountered driverName is the actually underlying driver, for example, `mysql`.
No description provided by the author
Rollback manually rollback all changes since last call on Load.

# Structs

Collection maps to a table.
No description provided by the author
Fixtures an utility to hold definitions of fixtures.

# Type aliases

Evaluator is used to generate data for columns.