Skip to content

Easy to use, simply designed package to help you with golden-file testing

License

Notifications You must be signed in to change notification settings

piotrowski/goldtest

Repository files navigation

goldtest

GoDoc Go Report Card codecov coverage

goldtest is a simple package that improves experience of working with golden files. It allows you to assert any type of data with saved golden file. Currently there are three exported functions, I believe it should be enough for most cases. If you see room for improvement, please leave an issue or pull request.

What is Golden file?

Golden file is another way to store "expected output" of a function. One "golden file" stands for output from one test case. Usually those files are stored in separated files, in directory "testdata".

Example usage is in example directory. Also you can read a little bit more about package in THIS blog post

You can read more about it here:

Usage

You can update(create) golden files automatically by providing flag -update.

There are two main functions:

Assert() - good for smaller files, there is no need to have any field exported, works good with []byte.
AssertJSON() - works good for big structs (E.g tree), will give you more readible golden file. If you want to use it, all fields that should be tested should be exported.

Both works similar for build-in types (Eg. string, int, float32 etc.). Output is a bit different for maps, structs and bytes.

I suggest using JSON when you have to work with big data structures as it will be more readable.

Note: As you can see here: Assert AssertJSON, there is wrong output, when using AssertJSON(). This is how it is, so if you want use golden_file for bytes, consider using Assert()

Example can be found in example directory

About

Easy to use, simply designed package to help you with golden-file testing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages