it

package module
v0.0.0-...-24333fe Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2015 License: MIT Imports: 6 Imported by: 0

README

it Build Status Coverage Status

An opinionated Integration Test "framework" for Go.

What it does

Basically, it helps you to start up a test server with all your routes, and, with a real database! It will create a new temporary database for you, run the migrations and, after the tests ran, delete it.

The idea is based on an internal framework that we made in Java at @ContaAzul.

What's opinionated

  • Your app uses a database and that it is PostgreSQL (about to change);
  • Your app is a web app;
  • Configuration comes from environment variables.

There are also other defaults, but you can override them using environment variables. Check the config.go file.

Talk is cheap, show me the code!

Check out the example folder!

You can easily run it with:

$ cd example
$ time go test
2015/10/13 22:41:07 Create-ing test database hkermdouni
2015/10/13 22:41:07 Connecting to postgres://localhost:5432/hkermdouni?sslmode=disable
2015/10/13 22:41:07 Migrate-ing database...
PASS
2015/10/13 22:41:07 Shutdown IT...
ok  	github.com/caarlos0/it/example	0.548s
go test  4.57s user 0.53s system 161% cpu 3.156 total

Lifecycle

  • Create a database with a random name in the provided POSTGRES_URL;
  • Run all .sql files in the MIGRATIONS_FOLDER against the created database;
  • Run the tests;
  • Drop the test database (unless DROP_TEST_DATABASE is false).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IT

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

IT is the main structure of the integration testing framework.

func New

func New() IT

New creates a new IT instance

func (*IT) Init

func (i *IT) Init(server ServerHandlerFn, connectToDatabase db.PoolFn) func(http.ResponseWriter, *http.Request)

Init the IT framework: loads config, creates the database and startup the server.

func (*IT) Shutdown

func (i *IT) Shutdown()

Shutdown the IT framework.

type ServerHandlerFn

type ServerHandlerFn func(*sql.DB) func(http.ResponseWriter, *http.Request)

ServerHandlerFn blah

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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