testutil

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 8 Imported by: 0

README

testutil

Utilities around cmp to help testing go code

Install

go get github.com/avakarev/go-testutil

Usage

package hello_test

import (
	"fmt"
	"testing"

	"github.com/avakarev/go-testutil"
)

func Hello() (string, error) {
	return "Hello World", nil
}

func TestHello(t *testing.T) {
	s, err := Hello()
	testutil.MustNoErr(err, t)
	testutil.Diff("Hello World", s, t)
}

License

go-testutil is licensed under MIT license. (see LICENSE)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(want interface{}, got interface{}, t *testing.T)

Diff fails the test if `want` differs from `got`, and prints human-readable error

func FixtureBytes added in v1.2.0

func FixtureBytes(t *testing.T, name string, args ...string) []byte

FixtureBytes returns content bytes of the given fixture

func FixturePath

func FixturePath(name string, args ...string) string

FixturePath returns absolute path to the given fixture

func FixtureReader added in v1.2.0

func FixtureReader(t *testing.T, name string, args ...string) *strings.Reader

FixtureReader returns io reader of the given fixture

func MustErr

func MustErr(want error, got error, t *testing.T)

MustErr fails the test if `want` error differs from `got` error

func MustNoErr

func MustNoErr(err error, t *testing.T)

MustNoErr fail the test if `err` is not nil

func SetEnv added in v1.1.0

func SetEnv(env Env) (reset func())

SetEnv set given Env value entries to the process's environment and returns reset function

Types

type Env added in v1.1.0

type Env map[string]string

Env is a helper type to declare map of environment variables key/value pairs

Jump to

Keyboard shortcuts

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