https://github.com/plouc/gosnap
:camera: gosnap is a go package to perform snapshot testing
https://github.com/plouc/gosnap
go golang snapshot-testing testing
Last synced: 12 months ago
JSON representation
:camera: gosnap is a go package to perform snapshot testing
- Host: GitHub
- URL: https://github.com/plouc/gosnap
- Owner: plouc
- License: mit
- Created: 2018-07-10T19:53:44.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-14T07:01:01.000Z (almost 8 years ago)
- Last Synced: 2025-02-28T06:19:09.122Z (over 1 year ago)
- Topics: go, golang, snapshot-testing, testing
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gosnap
[](https://travis-ci.org/plouc/gosnap)
[](https://godoc.org/github.com/plouc/gosnap)
[](https://github.com/plouc/gosnap/blob/master/LICENSE)
[](https://goreportcard.com/report/github.com/plouc/gosnap)
[](https://github.com/plouc/gosnap/issues)
**gosnap** is a go package to perform snapshot testing.
Snapshot testing is a convenient way to test large outputs with ease,
this package was initially created to test the [`go-gitlab-client` CLI](https://github.com/plouc/go-gitlab-client).
## Install
```
go get github.com/plouc/gosnap
```
## Usage
**gosnap** requires a context to run, from which you can create snapshots.
````go
package whatever
import (
"testing"
"github.com/plouc/gosnap"
)
func TestSomething(t *testing.T) {
// creates a new context
// snapshots will be stored inside the `snapshots` directory
ctx := gosnap.NewContext(t, "snapshots")
// creates a new snapshot
// it will be stored in `snapshots/my_first_snapshot.snap`
s := ctx.NewSnapshot("my_first_snapshot")
actual := DoSomethingWhichReturnsString()
// this will load the snapshot content and check it matches `actual`
s.AssertString(actual)
}
````
This will check that `actual` matches current snapshot (`./snapshots/my_first_snapshot.snap`) content.
The first time you run your tests, the snapshot will be created automatically,
then if the current result does not match snapshot's content, you'll have to
update it, you can add a command-line flag to the `go test command` to do so:
```
# will update all stale snapshots
go test -v ./... -args -update all
# will just update snapshot whose name is `my_snapshot`
go test -v ./... -args -update my_snapshot
```
For complete usage of **gosnap**, see the full [package docs](https://godoc.org/github.com/plouc/gosnap).