Categorygithub.com/blokur/testament
modulepackage
0.5.0
Repository: https://github.com/blokur/testament.git
Documentation: pkg.go.dev

# README

Testament

For all your testing needs.

Build Status

Testament

  1. Introduction
  2. Development

Introduction

These are common tools we usually use in our tests.

FunctionDescription
AssertInErrorCheck if an error is found in a deeply nested errors
RandomStringGenerates a randomly generated string by given length
GetFreeOpenPortReturns a port that is already claimed.
GetFreePortReturns a random open port.
RandomStringReturns a randomly generates string with the length of count.
RandomLowerStringReturns a randomly generates lower-cased string with a maximum length.
StringSliceReturn a string slice with the provided length.
RandomStringSliceReturn a random string slice with maximum length.
IntSliceReturns a slice of int elements with the provided length.
RandIntSliceReturns a slice of int elements with random length of less than n.
Int32Slice
RandInt32Slice
Int64Slice
RandInt64Slice
IntSliceComparerIs a go-cmp comparer that doesn't care if the slices are not sorted.
Int32SliceComparer
Int64SliceComparer
StringSliceComparer
RandomEmailAddressReturns a valid random email address.

Development

Prerequisite

This project supports Go >= 1.18. To run targets from the Makefile you need to install GNU make.

In order to install dependencies:

make dependencies

This also installs reflex to help with development process.

Running Tests

To watch for file changes and run unit_test:

make unit_test_watch
# or to run them with race flag:
make unit_test_race_watch

There is also a integration_test target for running integration tests.

Make Examples

make                           # shows help on targets.
make unit_test
make unit_test run=TestMyTest   # runs a specific test with regexp.
make unit_test dir=./path/...   # runs tests in a package.
make unit_test dir=./path/... run=TestSomethingElse

Please see the Makefile for more targets.

# Functions

AssertInError returns true if the needle is found in stack, which is created either with pkg/errors help, the multierror or Go's error wrap.
AssertIsCode is a helper to assert the err error contains the code.
GetFreeOpenPort returns a port that is already claimed.
GetFreePort returns a random open port.
Int32Slice returns a slice of int32 elements with provided length.
Int64Slice returns a slice of int64 elements with provided length.
IntSlice returns a slice of int elements with the provided length.
RandInt32Slice returns a slice of int32 elements with random length of less than n.
RandInt64Slice returns a slice of int64 elements with random length of less than n.
RandIntSlice returns a slice of int elements with random length of less than n.
RandomEmailAddress returns a random email address.
RandomLowerString returns a randomly generates lower-cased string with the length of count.
RandomS3Filename returns a random S3 filename with a subfolder.
RandomString returns a randomly generates string with the length of count.
RandomStringSlice return a random string slice with maximum length of to.
RandUint32Slice returns a slice of uint32 elements with random length of less than n.
RandUint64Slice returns a slice of uint64 elements with random length of less than n.
RandUintSlice returns a slice of uint elements with random length of less than n.
StringSlice return a string slice with the provided length.
Uint32Slice returns a slice of uint32 elements with provided length.
Uint64Slice returns a slice of uint64 elements with provided length.
UintSlice returns a slice of uint elements with the provided length.

# Variables

Int32SliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted.
Int64SliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted.
IntSliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted.
StringSliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted.
Uint32SliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted.
Uint64SliceComparer is a go-cmp comparer that doesn't care if the slices in question is not sorted.