File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package core
22
33import (
4+ "bytes"
5+ "io"
6+ "log"
47 "net/http"
58 "regexp"
69 "testing"
@@ -27,6 +30,9 @@ func cassetteResponseFilter(i *cassette.Interaction) error {
2730 i .Request .URL = regexp .MustCompile (`pack\.local%2Fbuilder%2F[0-9a-f]{20}` ).ReplaceAllString (i .Request .URL , "pack.local%2Fbuilder%2F11111111111111111111" )
2831 i .Request .URL = regexp .MustCompile (`pack\.local/builder/[0-9a-f]{20}` ).ReplaceAllString (i .Request .URL , "pack.local/builder/11111111111111111111" )
2932
33+ i .Request .Body = regexp .MustCompile (`pack\.local/builder/[0-9a-f]{20}` ).ReplaceAllString (i .Response .Body , "pack.local/builder/11111111111111111111" )
34+ i .Response .Body = regexp .MustCompile (`pack\.local/builder/[0-9a-f]{20}` ).ReplaceAllString (i .Response .Body , "pack.local/builder/11111111111111111111" )
35+
3036 return nil
3137}
3238
@@ -39,6 +45,15 @@ func cassetteMatcher(r *http.Request, i cassette.Request) bool {
3945 r .URL .RawQuery = regexp .MustCompile (`pack\.local%2Fbuilder%2F[0-9a-f]{20}` ).ReplaceAllString (r .URL .RawQuery , "pack.local%2Fbuilder%2F11111111111111111111" )
4046 r .URL .Path = regexp .MustCompile (`pack\.local/builder/[0-9a-f]{20}` ).ReplaceAllString (r .URL .Path , "pack.local/builder/11111111111111111111" )
4147
48+ if r .Body != nil && r .Body != http .NoBody {
49+ reqBody , err := io .ReadAll (r .Body )
50+ if err != nil {
51+ log .Fatal ("failed to read request body" )
52+ }
53+ r .Body .Close ()
54+ r .Body = io .NopCloser (bytes .NewBuffer (reqBody ))
55+ }
56+
4257 return cassette .DefaultMatcher (r , i )
4358}
4459
You can’t perform that action at this time.
0 commit comments