Categorygithub.com/pirmd/verify
modulepackage
0.8.0
Repository: https://github.com/pirmd/verify.git
Documentation: pkg.go.dev

# README

VERIFY

GoDoc  Go Report Card 

verify package is a collection of simple functions that I find handy to use for building my unit testing.

INSTALLATION

Everything should work fine using go standard commands (build, get, install...).

USAGE

Running go doc github.com/pirmd/verify should give you helpful guidelines on availables features.

With the package set-up, additional go test flags are offered: . -test.golden-update: updates the golden files with the test result. . -test.mockhttp-update: updates files served through the mock-http transport. . -test.diff: show differences between the test result and expected values. . -test.diff-color: show differences in color between the test result and the expected values. . -test.diff-np: show differences between result and expected values materializing non printable chars.

CONTRIBUTION

If you feel like to contribute, just follow github guidelines on forking then send a pull request

# Functions

DirHasContent checks that the given dir contains the provided tree.
DirIsEmpty checks that a dir is empty.
Equal verifies that 'got' is equal to 'want'.
EqualSliceWithoutOrder verifies that two slices of strings are equal whatever the order of their content is.
EqualStdoutString verifies that captured os.Stdout is equal to 'want' and feedback a test error message with a line by line diff between them.
FileDoesNotExist checks if provided path does not exist.
FileExists checks if provided path exists.
MatchGolden compares a test result to the content of a 'golden' file If 'update' command flag is used, update the 'golden' file.
MatchStdoutGolden compares captured os.Stdout to the content of a 'golden' file If 'update' command flag is used, update the 'golden' file.
MockROFile returns a bytes.Buffer backed mock File that implements io.Reader, io.Seeker, io.ReaderAt interfaces.
MustNewTestFolder creates a temporary folder to host a test folder for tb.
NewLogger returns a new logger that logs to the provided testing.TB.
NewMockHTTPResponse creates a new MockHTTPResponse returning content stored in mockHTTPDir.
NewMockStdout creates a new record session of os.Sdtout and start capture operation.
Panic verifies that the given func will panic when run.
StartMockHTTPResponse creates a new MockHTTPResponse and starts it.
StartMockStdout creates a new record session of os.Sdtout and start capture operation.

# Variables

GoldenDir is the path where to find golden files.

# Structs

MockHTTPResponse represents a mock http transport for testing purpose.
MockStdout is an helper to capture output to Stdout.
TestFolder represents a temporary folder where testing can happen.

# Interfaces

MockReader is an interface that offers most of os.File reading operations.