polluter

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GoDoc Go Report Card Build Status

polluter

Mainly this package was created for testing purposes, to give the ability to seed a database with records from simple .yaml files. Polluter respects the order in files, so you can handle foreign_keys just by placing them in the right order.

Usage

package main

import "github.com/johnbenedictyan/polluter"

const input = `
roles:
- name: User
users:
- name: Roman
  role_id: 1
`

func TestX(t *testing.T) {
	db := prepareMySQL(t)
	defer db.Close()
	p := polluter.New(polluter.MySQLEngine(db))

	if err := p.Pollute(strings.NewReader(input)); err != nil {
		t.Fatalf("failed to pollute: %s", err)
	}

	....
}

Examples

See examples of usage with parallel testing.

Testing

Make shure to start docker before testing.

go test

Supported databases

  • MySQL
  • Postgres
  • Redis

Contributing

Please feel free to submit issues, fork the repository and send pull requests!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEngineNotSpecified causes if no engine option was used
	// with the factory method.
	ErrEngineNotSpecified = errors.New("specify database engine with the factory method option")
)

Functions

func JSONParser

func JSONParser(p *Polluter)

JSONParser option enables JSON parsing engine for seeding.

func YAMLParser

func YAMLParser(p *Polluter)

YAMLParser option enables YAML parsing engine for seeding.

Types

type CustomMap added in v1.0.2

type CustomMap = map[string]any

type Option

type Option func(*Polluter)

Option defines options for Polluter.

func MySQLEngine

func MySQLEngine(db *sql.DB) Option

MySQLEngine option enables MySQL engine for poluter.

func PostgresEngine

func PostgresEngine(db *sql.DB) Option

PostgresEngine option enables Postgres engine for Polluter.

func RedisEngine

func RedisEngine(cli *redis.Client) Option

RedisEngine option enables Redis engine for Polluter.

type Polluter

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

Polluter pollutes database with given input.

func New

func New(options ...Option) *Polluter

New factory method returns initialized Polluter. For example to seed MySQL database with JSON input use:

p := New(MySQLEngine(db))

To seed Postgres database with YAML input use:

p := New(PostgresEngine(db), YAMLParser)

func (*Polluter) Pollute

func (p *Polluter) Pollute(r io.Reader) error

Pollute parses input from the reader and tries to exec generated commands on a database. Use New factory function to generate.

Jump to

Keyboard shortcuts

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