testutil

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 7 Imported by: 0

README

testutil

Utility helpers for testing, based on go-cmp

Install

go get github.com/avakarev/go-util/testutil

Usage

package hello_test

import (
	"fmt"
	"testing"

	"github.com/avakarev/go-util/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

Overview

Package testutil implements helpers for testing, based on go-cmp

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

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

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

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

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

Types

type Env

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