@@ -35,7 +35,6 @@ var SensitiveFields = map[string]interface{}{
3535// QueryMatcherIgnore contains the list of query value that should be ignored when matching requests with cassettes
3636var QueryMatcherIgnore = []string {
3737 "organization_id" ,
38- "project_id" ,
3938}
4039
4140// BodyMatcherIgnore contains the list of json body keys that should be ignored when matching requests with cassettes
@@ -236,6 +235,30 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
236235 cassetteBodyMatcher (actual , expected )
237236}
238237
238+ // cassetteMatcherWithoutProjectID is a custom matcher that check equivalence of a played request against a recorded one
239+ // It compares method, path and query but will remove unwanted values from query
240+ func cassetteMatcherWithoutProjectID (actual * http.Request , expected cassette.Request ) bool {
241+ expectedURL , _ := url .Parse (expected .URL )
242+ actualURL := actual .URL
243+ actualURLValues := actualURL .Query ()
244+ expectedURLValues := expectedURL .Query ()
245+
246+ for _ , query := range QueryMatcherIgnore {
247+ actualURLValues .Del (query )
248+ expectedURLValues .Del (query )
249+ }
250+ actualURLValues .Del ("project_id" )
251+ expectedURLValues .Del ("project_id" )
252+
253+ actualURL .RawQuery = actualURLValues .Encode ()
254+ expectedURL .RawQuery = expectedURLValues .Encode ()
255+
256+ return actual .Method == expected .Method &&
257+ actual .URL .Path == expectedURL .Path &&
258+ actualURL .RawQuery == expectedURL .RawQuery &&
259+ cassetteBodyMatcher (actual , expected )
260+ }
261+
239262func cassetteSensitiveFieldsAnonymizer (i * cassette.Interaction ) error {
240263 var jsonBody map [string ]interface {}
241264
@@ -267,7 +290,7 @@ func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error {
267290//
268291// It is important to add a `defer cleanup()` so the given cassette files are correctly
269292// closed and saved after the requests.
270- func getHTTPRecoder (t * testing.T , pkgFolder string , update bool ) (client * http.Client , cleanup func (), err error ) {
293+ func getHTTPRecoder (t * testing.T , pkgFolder string , update bool , matcherFunc cassette. MatcherFunc ) (client * http.Client , cleanup func (), err error ) {
271294 t .Helper ()
272295
273296 recorderMode := recorder .ModeReplayOnly
@@ -298,7 +321,7 @@ func getHTTPRecoder(t *testing.T, pkgFolder string, update bool) (client *http.C
298321 }(r )
299322
300323 // Add custom matcher for requests and cassettes
301- r .SetMatcher (cassetteMatcher )
324+ r .SetMatcher (matcherFunc )
302325
303326 // Add a filter which removes Authorization headers from all requests:
304327 r .AddHook (func (i * cassette.Interaction ) error {
0 commit comments