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

Fix: make DefaultMatcher strict #98

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

fornellas-udemy
Copy link
Contributor

Ditto.

Closes #97.

@fornellas-udemy fornellas-udemy marked this pull request as ready for review June 17, 2024 11:44
@dnaeon dnaeon merged commit 8d81b8e into dnaeon:v3 Jun 17, 2024
2 checks passed
@dnaeon
Copy link
Owner

dnaeon commented Jun 17, 2024

Merged, thanks!

@fornellas-udemy
Copy link
Contributor Author

@dnaeon as this is now, it is definitely safe, but I bumped into a corner case today, that you may want to consider updating. Some libraries set the user agent header with things like GOOS and GOARCH, which means that, the fixture would have for example linux/amd64 from one machine, and the build would fail on another machine which is darwin/arm64 for example. It should be safe-ish to ignore the user agent in the default case:

	// User-Agent sometimes contain GOOS or GOARCH values, which breaks the build across different
	// machines. We ignore these to prevent this issue.
	requestHeader := maps.Clone(request.Header)
	delete(requestHeader, "User-Agent")
	cassetteRequestHeaders := maps.Clone(cassetteRequest.Headers)
	delete(cassetteRequestHeaders, "User-Agent")
	if !deepEqualContents(requestHeader, cassetteRequestHeaders) {
		return false
	}

Maybe we could have this as some sort of option? Safe by default, but trivial to tweak? WDYT?

@dnaeon
Copy link
Owner

dnaeon commented Jul 24, 2024

Hey @fornellas-udemy ,

I'm okay with adding such functionality, however I don't have spare time these days to actually work on it, but would be happy to review any proposed changes.

Thanks!

@fornellas-udemy
Copy link
Contributor Author

NP, I'll cook a PR then, TY.

@fornellas-udemy fornellas-udemy deleted the add_strict_matcher branch August 1, 2024 10:35
@fornellas-udemy fornellas-udemy mentioned this pull request Aug 1, 2024
@jsoriano
Copy link

jsoriano commented Aug 5, 2024

It looks like this change (and/or #99) breaks existing tests, would it be possible to make this stricter mode optional, and maybe later consider making it the default in a future major?

We have found that updating from 3.2.0 to 3.2.1 (elastic/elastic-package#2001) breaks all our tests that make use of go-vcr, what is unexpected for a patch version. Regenerating all our recorded interactions would be burdensome.

Apart of that there are header fields or part of bodies that may change between executions, for example the multipart writer in the Go stdlib includes randomly generated boundaries.

@dnaeon
Copy link
Owner

dnaeon commented Aug 5, 2024

@jsoriano I've just retracted v3.2.1

4bc3b10

Users can still install v3.2.1 but for now it is retracted. Will be carving out a new minor release soon, sorry for the inconvenience.

@jsoriano
Copy link

jsoriano commented Aug 5, 2024

Thanks @dnaeon for the quick answer, let me know if we can help testing the new release, vcr has helped a lot improving the reliability and speed of our builds!

@fornellas-udemy
Copy link
Contributor Author

Apart of that there are header fields or part of bodies that may change between executions, for example the multipart writer in the Go stdlib includes randomly generated boundaries.

Hum... @jsoriano it looks like this may be another case to extend on #99, as I can see how this logic would be reusable across various projects.

@dnaeon
Copy link
Owner

dnaeon commented Aug 18, 2024

Hey @fornellas-udemy and @jsoriano , I've just pushed the v4 branch. We will use that one for the next release of go-vcr.

@fornellas-udemy
Copy link
Contributor Author

@dnaeon I see you changed v4 to make heavy use of the foo.NewFoo(foo.WithBar()...) pattern. While this works, I is objectively more complex (than a simple type Options struct for example), and will require me (and others) to push a fair amount of code refactoring to upgrade. In my cases in particular, as I had a base recorder object, which I decorated on a per-test basis with extra stuff, I'll have to update virtually everything to pile up Option functions, delay the recorder creation until the end. Doable, but I feel like it'll be a lot of code & energy, for no tangible gain. If we look at HTTP server design for example, it is just a simple object, no need for a lot of methods and complications on top.

Is this design something you're strongly attached to, or are you open to exploring options?

@dnaeon
Copy link
Owner

dnaeon commented Aug 20, 2024

Hey @fornellas-udemy ,

Perhaps we can open up a separate issue and discuss this as part of the v4 release? Also, if you could provide some examples and code why do you think going with the older options might be a better choice, or not, that would be really helpful.

Thanks!

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

Successfully merging this pull request may close these issues.

DefaultMatcher isn't strict
3 participants