testament

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

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.

+----------------+------------------------------------------------------+
| AssertInError | Check if an error is found in a deeply nested errors  |
| RandomString  | Generates a randomly generated string by given length |
+----------------+------------------------------------------------------+

Development

Prerequisite

This project supports Go > 1.14. 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.

Changelog

You need to update the changelogs file before each release. In order to update the changelogs file run the following:

make changelog

When you are ready to make a commitment and tag the next release, use this target and pass in the next tag:

make changelog_release tag=v1.0.1

Documentation

Overview

Package testament provides convinience tools in testing.

AssertInError

If you have a deeply nested error you want to check whether a particular error is in the haystack you can call this function. It will upwrap everything made from any of or any combination of fmt.Errorf, hashicorp/go-multierror, and pkg/errors helpers. It will fallback to the string representation of the error being in the haystack string representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertInError

func AssertInError(t *testing.T, haystack, needle error) bool

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. It will fall back to checking the contents of the needle.Error() is in haystack.Error().

func AssertIsCode added in v0.1.0

func AssertIsCode(t *testing.T, err error, code codes.Code) bool

AssertIsCode is a helper to assert the err error contains the code.

func GetFreeOpenPort added in v0.1.0

func GetFreeOpenPort(t *testing.T) (uint, net.Listener)

GetFreeOpenPort returns a port that is already claimed.

func GetFreePort added in v0.1.0

func GetFreePort(t *testing.T) uint

GetFreePort returns a random open port.

func RandomString added in v0.1.0

func RandomString(count int) string

RandomString returns a randomly generated string with the length of count.

Types

This section is empty.

Jump to

Keyboard shortcuts

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