Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to skip certain interactions from getting saved to disk #80

Closed
sergiught opened this issue Oct 25, 2022 · 1 comment
Closed

Comments

@sergiught
Copy link

Describe the problem you'd like to have solved

I'd like to have a way to specify which kind of Interaction to skip from being recorded on disk inside a cassette. This would be useful for example if I don't want the cassette spammed with 429s.

Describe the ideal solution

Perhaps something like:

recorder.AddHook(
	func(i *cassette.Interaction) error {
		if i.Response.Code == http.StatusTooManyRequests {
			i.Skip()
			return nil
		}
		return nil
	},
	recorder.BeforeSaveHook,
)

Alternatives and current workarounds

Current workaround would be to manually remove them from the cassette file.

Additional context

Thanks a lot for maintaining this! It's a great project. 👍🏻

dnaeon added a commit that referenced this issue Oct 25, 2022
The DiscardOnSave field may be set to true by hooks, in order to
discard an interaction before saving it on disk.

See issue #80 for some background info.
@dnaeon
Copy link
Owner

dnaeon commented Oct 25, 2022

@sergiught , please check #81 and let me know what do you think?

Example hook you could set looks like this.

	hook := func(i *cassette.Interaction) error {
		if i.Request.Method == http.MethodPost && i.Request.Body == "foo" {
			i.DiscardOnSave = true
		}

		return nil
	}

dnaeon added a commit that referenced this issue Oct 25, 2022
The DiscardOnSave field may be set to true by hooks, in order to
discard an interaction before saving it on disk.

See issue #80 for some background info.
@dnaeon dnaeon closed this as completed Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants