charlatan

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 5 Imported by: 0

README

Build Status Go Report Card codecov

Charlatan - Expressive fixtures generator

Relying on brianvoe/gofakeit, Charlatan allows you to create a ton of fixtures/fake data for use while developing or testing your project. It is inspired by nelmio/alice.It gives you a few essential tools to make it very easy to generate complex data in a readable and easy to edit way, so that everyone on your team can tweak the fixtures if needed.

Table of content

  1. Installation
  2. Example
  3. Complete Reference
  4. Handling Relations
  5. Data generator

Installation

First, get it:

go get -u github.com/msales/charlatan

Internal Postgres test database service.

Use internal postgres database fixture loader and rebuilder for ease of use
cfg := postgres_test.Config{
    Host:          "localhost",
    Port:          5432,
    User:          "user",
    Password:      "pass",
    MainDirectory: "project-root",
    FixturesPath:  "/fixtures"
    ProjectPath:   "/app",
    Migrations:    yourMigrations,
    OverrideFunc:  postgres_test.GithubActionsOverride, // use this when you use Github Actions tests.
}

postgres_test.Initialize(cfg) // initialize template and test database

postgres_test.RebuildDatabase() // clear database and rebuild with fresh data from fixtures.

db := postgres_test.TestDB() // connect to test database
db := postgres_test.TemplateDB() // connect to template database

Create file in another package that will wrap postgres_test.RebuildDatabase(). E.g. test/functional.go

This way you assure test and template database initialization for every functional test that uses test database builder.

func init() {
	postgres_test.Initialize(createConfig())
}

// RebuildDatabase is wrapper around charlatan's internal rebuilder so init will always happen.
func RebuildDatabase() {
	postgres_test.RebuildDatabase()
}

Example

Here is a complete example of a declaration:

user:
    user_tpl (template):
        first_name: '<FirstName()>'
        last_name: '<LastName()>'
        pseudo: '<UserName()>'
        password: '<Words(2,true)>'
        email : '<Email()>'
    admin_1:
        first_name: 'William'
        last_name: 'Wallace'
        pseudo: 'WW'
        password: 'freedommmmmmm'
        email : 'freedom@gouv.co.uk'
        isAdmin: true
    admin_{2..5} (extends user_tpl):
        isAdmin: true
    user_{bob,harry,george} (extends user_tpl):
        isAdmin: false

You can then load them easily with:

charlatan load --fixtures ./fixtures --user=<your_db_user> --dbname=<your_dbname> --pass=<your_db_pass>

Compatible databases

  • MySQL / MariaDB
  • PostgreSQL (in progress)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBOptions

type DBOptions struct {
	Host     string
	Username string
	Password string
	Name     string
	Port     int16
}

DBOptions are database options for connection

type Fixtures

type Fixtures interface {
	// Load searches for yaml files in fixturesPath and tries to load it to db
	Load(fixturePath string) error
}

Fixtures represents a charlatan fixtures service

func NewFixtures

func NewFixtures(opts DBOptions) Fixtures

NewFixtures returns new fixtures loader

Directories

Path Synopsis
pkg
services

Jump to

Keyboard shortcuts

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