Skip to content

Commit

Permalink
Fail tests if no snapshot exists (#43)
Browse files Browse the repository at this point in the history
* Update cupaloy.go

```
cupaloy.Global = cupaloy.Global.WithOptions(
		cupaloy.CreateNewAutomatically(false),
		cupaloy.EnvVariableName(updateSnapshotsEnv),
		cupaloy.FailOnUpdate(false),
		cupaloy.ShouldUpdate(func() bool { return updateSnapshot}),
		cupaloy.SnapshotSubdirectory(updateSnapshotsDir),
	)
```

Sorry missed this earlier. This is the set of config I'm using. When snapshots don't exist and I'm running in bazel setting it is not failing as expected.

* Update unit tests

* Update assert called with mock.Anything
  • Loading branch information
byang223 authored and bradleyjkemp committed Sep 20, 2018
1 parent ea4d415 commit 5859e8d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cupaloy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func (c *Config) snapshot(snapshotName string, i ...interface{}) error {
if c.createNewAutomatically {
return c.updateSnapshot(snapshotName, snapshot)
}
//TODO: should an error still be printed here?
return nil
return fmt.Errorf("snapshot does not exist for test %s", snapshotName)
}
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions examples/advanced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ func TestGlobalCreateNewAutomatically(t *testing.T) {
mockT.On("Helper").Return()
mockT.On("Failed").Return(false)
mockT.On("Name").Return(t.Name())
mockT.On("Error", mock.Anything).Return()

cupaloy.SnapshotT(mockT, "This should fail because doesn't exist")
mockT.AssertNotCalled(t, "Error")
mockT.AssertCalled(t, "Error", mock.Anything)
}

func TestFailOnUpdate(t *testing.T) {
Expand All @@ -184,4 +185,4 @@ func TestFailOnUpdate(t *testing.T) {
}

snapshotter.Snapshot("Hello world") // reset snapshot to known state (ignoring return value)
}
}

0 comments on commit 5859e8d

Please sign in to comment.