test

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package test contains helper functions to remove common boilerplate to make testing easier.

The ExpectEquality() is the most basic and probably the most useful function. It compares like-typed variables for equality and returns true if they match. ExpectInequality() is the inverse function.

The ExpectFailure() and ExpectSuccess() functions test for failure and success. These two functions work with bool or error and special handling for nil.

ExpectImplements() tests whether an instance implements the specified type.

The Writer type meanwhile, implements the io.Writer interface and should be used to capture output. The Writer.Compare() function can then be used to test for equality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectEquality added in v0.25.0

func ExpectEquality[T comparable](t *testing.T, value T, expectedValue T)

ExpectEquality is used to test equality between one value and another

func ExpectFailure added in v0.25.0

func ExpectFailure(t *testing.T, v interface{}) bool

ExpectFailure tests argument v for a failure condition suitable for it's type. Types bool and error are treated thus:

bool == false
error != nil

If type is nil then the test will fail

func ExpectImplements added in v0.30.0

func ExpectImplements[T comparable](t *testing.T, instance any, implements T)

ExpectImplements tests whether an instance is an implementation of type T

func ExpectInequality added in v0.25.0

func ExpectInequality[T comparable](t *testing.T, value T, expectedValue T)

ExpectInequality is used to test inequality between one value and another. In other words, the test does not want to succeed if the values are equal

func ExpectSuccess added in v0.25.0

func ExpectSuccess(t *testing.T, v interface{}) bool

ExpectSuccess tests argument v for a success condition suitable for it's type. Types bool and error are treated thus:

bool == true
error == nil

If type is nil then the test will succeed

Types

type Writer

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

Writer is an implementation of the io.Writer interface. It should be used to capture output and to compare with predefined strings.

func (*Writer) Clear added in v0.3.4

func (tw *Writer) Clear()

clear string empties the buffer.

func (*Writer) Compare

func (tw *Writer) Compare(s string) bool

Compare buffered output with predefined/example string.

func (*Writer) String added in v0.3.4

func (tw *Writer) String() string

implements Stringer interface.

func (*Writer) Write

func (tw *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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