testutils

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 9 Imported by: 0

README

testutils

Test toolkit for simplify the development of tests on Go

This package contains universal interfaces and utilities for handling errors in tests and benchmarks

Example
package some_test

import (
	"testing"
	"time"

	_ "github.com/go-sql-driver/mysql"
	
	"github.com/partyzanex/testutils"
)

func TestSomeTestName(t *testing.T) {
	// supported mysql and postgres
	db := testutils.NewSqlDB(t, "postgres", "TEST_DSN")

	rows, err := db.Query(`select id, name from tbl where dt > ?`, time.Now())
	testutils.FatalErr(t, "db.Query", err)

	// ...
}

Run:

export TEST_DSN="user=postgres password=password sslmode=disable dbname=testdb"

go test ./path/to/some -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t Tester, _ string, exp, got interface{})

func AssertEqualFatal

func AssertEqualFatal(t Tester, name string, exp, got interface{})

func Err

func Err(t Tester, name string, err error)

func FatalErr

func FatalErr(t Tester, name string, err error)

func NewSqlDB

func NewSqlDB(t Tester, driverName, envName string) *sql.DB

NewDB create and returns new *sql.DB from environment in your tests you need to add sql drivers manually _ "github.com/ClickHouse/clickhouse-go" _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq"

func RandFloat64

func RandFloat64(min, max float64) float64

func RandInt

func RandInt(min, max int) int

func RandInt64

func RandInt64(min, max int64) int64

func RandomCase added in v0.0.8

func RandomCase(args ...interface{}) interface{}

func RandomDate

func RandomDate(min, max time.Time) time.Time

func RandomIP

func RandomIP() string

func RandomImage added in v0.0.9

func RandomImage(width, height int) image.Image

func RandomString

func RandomString(n int) string

Types

type Tester

type Tester interface {
	Skip(args ...interface{})
	Skipf(format string, args ...interface{})

	Log(args ...interface{})
	Logf(format string, args ...interface{})

	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})

	Error(args ...interface{})
	Errorf(format string, args ...interface{})
}

Jump to

Keyboard shortcuts

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