Skip to content

Commit c1836c1

Browse files
committed
custom matcher for Docker which escapes URL before comparison
1 parent a035734 commit c1836c1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/testing_recorder.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ func cassetteMatcher(r *http.Request, i cassette.Request) bool {
8686
return customS3Matcher(r, i)
8787
}
8888

89+
// Specific handling of Docker URLs
90+
// URLs are stored unescaped in the cassette but the matcher expects an escaped URL
91+
if r.URL.Host == unixDockerEngine {
92+
return customDockerMatcher(r, i)
93+
}
94+
8995
return cassette.DefaultMatcher(r, i)
9096
}
9197

@@ -125,6 +131,14 @@ func customS3Matcher(r *http.Request, i cassette.Request) bool {
125131
actualURL.RawQuery == expectedURL.RawQuery
126132
}
127133

134+
func customDockerMatcher(r *http.Request, i cassette.Request) bool {
135+
escapedRecordedURL := regexp.MustCompile(`http://`+unixDockerEngine+`(.+)?`).
136+
ReplaceAllString(
137+
i.URL,
138+
"http://"+escapedUnixDockerEngine+"${1}")
139+
return r.URL.String() == escapedRecordedURL
140+
}
141+
128142
func unescapeDockerURL(i *cassette.Interaction) error {
129143
i.Request.URL = regexp.MustCompile(`http://`+escapedUnixDockerEngine+`(.+)?`).
130144
ReplaceAllString(

0 commit comments

Comments
 (0)