diff --git a/cassette/cassette.go b/cassette/cassette.go index 75358f1..a302800 100644 --- a/cassette/cassette.go +++ b/cassette/cassette.go @@ -186,16 +186,13 @@ func transformInterfacesInJSON(jsonString []byte) []byte { return []byte(regex.ReplaceAllString(string(jsonString), `$1"$2",`)) } -// RecordNewTrackToCassette saves a new track using the specified details to a cassette. -func RecordNewTrackToCassette(cassette *Cassette, req *Request, resp *Response, httpErr error) error { - // create track - t := NewTrack(req, resp, httpErr) - +// AddTrackToCassette saves a new track using the specified details to a cassette. +func AddTrackToCassette(cassette *Cassette, aTrack *Track) error { // mark track as replayed since it's coming from a live Request! - t.Replayed(true) + aTrack.Replayed(true) // add track to cassette - cassette.AddTrack(t) + cassette.AddTrack(aTrack) // save cassette return cassette.save() diff --git a/controlpanel.go b/controlpanel.go index d413da4..7959fa6 100644 --- a/controlpanel.go +++ b/controlpanel.go @@ -24,7 +24,7 @@ func (controlPanel *ControlPanel) LoadCassette(cassetteName string) error { // LoadCassette into the VCR. func (controlPanel *ControlPanel) AddMutators(trackMutators ...TrackMutator) { - controlPanel.vcrTransport().addMutators(trackMutators...) + controlPanel.vcrTransport().AddMutators(trackMutators...) } // Player returns the http.Client that contains the VCR. diff --git a/govcr_wb_test.go b/govcr_wb_test.go index f3194ac..7280a16 100644 --- a/govcr_wb_test.go +++ b/govcr_wb_test.go @@ -61,9 +61,15 @@ func TestRoundTrip_SavesMutatedCassetteTracks(t *testing.T) { } require.EqualValues(t, expectedStats, actualStats) - // TODO now need to verify what is on the cassette has been mutated + err = vcr.LoadCassette(cassetteName) + assert.NoError(t, err) - t.Fatal("implement me - SHOULD TEST TRACKREPLAYMUTATOR") + for trackNum, aTrack := range vcr.vcrTransport().cassette.Tracks { + require.EqualValues(t, "GET has been mutated", aTrack.Request.Method, "track #%d", trackNum) + require.EqualValues(t, "200 OK has been mutated", aTrack.Response.Status, "track #%d", trackNum) + require.EqualValues(t, "ErrType was mutated", aTrack.ErrType, "track #%d", trackNum) + require.EqualValues(t, "ErrMsg was mutated", aTrack.ErrMsg, "track #%d", trackNum) + } } func makeHTTPCalls_WithSuccess(testServerURL string, vcr *ControlPanel, t *testing.T) stats.Stats { diff --git a/pcb.go b/pcb.go index f7fe1e2..3866665 100644 --- a/pcb.go +++ b/pcb.go @@ -52,6 +52,10 @@ func (pcbr *pcb) mutateTrack(t *cassette.Track) { pcbr.trackRecordingMutators.Mutate(t) } +func (pcbr *pcb) AddMutators(mutators ...TrackMutator) { + pcbr.trackRecordingMutators = pcbr.trackRecordingMutators.Add(mutators...) +} + // RequestMatcher is an interface that exposes the method to perform request comparison. // request comparison involves the HTTP request and the track request recorded on cassette. type RequestMatcher interface { diff --git a/vcrsettings.go b/vcrsettings.go index 47d2579..bee3fe8 100644 --- a/vcrsettings.go +++ b/vcrsettings.go @@ -45,7 +45,7 @@ func WithCassette(cassetteName string) Setting { // a cassette to load. func WithTrackRecordingMutators(trackRecordingMutators ...TrackMutator) Setting { return func(vcrConfig *VCRSettings) { - vcrConfig.trackRecordingMutators.Add(trackRecordingMutators...) + vcrConfig.trackRecordingMutators = vcrConfig.trackRecordingMutators.Add(trackRecordingMutators...) } } diff --git a/vcrtransport.go b/vcrtransport.go index 334dcd2..52c4ae2 100644 --- a/vcrtransport.go +++ b/vcrtransport.go @@ -37,8 +37,8 @@ func (t *vcrTransport) RoundTrip(httpRequest *http.Request) (*http.Response, err newTrack := cassette.NewTrack(request, response, reqErr) t.pcb.mutateTrack(newTrack) - if err := cassette.RecordNewTrackToCassette(t.cassette, request, response, reqErr); err != nil { - log.Printf("RoundTrip failed to RecordNewTrackToCassette: %v\n", err) + if err := cassette.AddTrackToCassette(t.cassette, newTrack); err != nil { + log.Printf("RoundTrip failed to AddTrackToCassette: %v\n", err) } return httpResponse, reqErr @@ -68,8 +68,8 @@ func (t *vcrTransport) ejectCassette() { t.cassette = nil } -func (t *vcrTransport) addMutators(mutators ...TrackMutator) { - t.pcb.trackRecordingMutators.Add(mutators...) +func (t *vcrTransport) AddMutators(mutators ...TrackMutator) { + t.pcb.AddMutators(mutators...) } func (t *vcrTransport) stats() *stats.Stats {