Skip to content

Commit

Permalink
fix: remove references to ControlPanel.LoadCassette (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
seborama authored Aug 24, 2022
1 parent 1b88cd3 commit af90e26
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ This structure contains parameters for configuring your **govcr** recorder.
Settings are populated via `With*` options:

- Use `WithClient` to provide a custom http.Client otherwise the default Go http.Client will be used.
- `WithCassette` loads the specified cassette.\
Note that it is also possible to call `LoadCassette` from the vcr instance.
- `WithCassette` loads the specified cassette.
- See `vcrsettings.go` for more options such as `WithRequestMatcher`, `WithTrackRecordingMutators`, `WithTrackReplayingMutators`, ...
- TODO: `WithLogging` enables logging to help understand what **govcr** is doing internally.

Expand Down
26 changes: 13 additions & 13 deletions govcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ func (ts *GoVCRTestSuite) TearDownTest() {
type action int

const (
actionKeep = iota
actionDelete
actionKeepCassette = iota
actionDeleteCassette
)

func (ts *GoVCRTestSuite) loadCassette(cassetteName string, a action) *govcr.ControlPanel {
if a == actionDelete {
func (ts *GoVCRTestSuite) newVCR(cassetteName string, a action) *govcr.ControlPanel {
if a == actionDeleteCassette {
_ = os.Remove(cassetteName)
}

Expand All @@ -145,7 +145,7 @@ func (ts *GoVCRTestSuite) loadCassette(cassetteName string, a action) *govcr.Con
func (ts *GoVCRTestSuite) TestVCR_ReadOnlyMode() {
const k7Name = "temp-fixtures/TestGoVCRTestSuite.TestVCR_ReadOnlyMode.cassette.json"

vcr := ts.loadCassette(k7Name, actionDelete)
vcr := ts.newVCR(k7Name, actionDeleteCassette)
vcr.SetReadOnlyMode(true)

resp, err := vcr.HTTPClient().Get(ts.testServer.URL)
Expand All @@ -166,7 +166,7 @@ func (ts *GoVCRTestSuite) TestVCR_LiveOnlyMode() {
const k7Name = "temp-fixtures/TestGoVCRTestSuite.TestVCR_LiveOnlyMode.cassette.json"

// 1st execution of set of calls
vcr := ts.loadCassette(k7Name, actionDelete)
vcr := ts.newVCR(k7Name, actionDeleteCassette)
vcr.SetLiveOnlyMode()
vcr.SetRequestMatcher(govcr.NewBlankRequestMatcher()) // ensure always matching

Expand All @@ -181,7 +181,7 @@ func (ts *GoVCRTestSuite) TestVCR_LiveOnlyMode() {
ts.Require().FileExists(k7Name)

// 2nd execution of set of calls
vcr = ts.loadCassette(k7Name, actionKeep)
vcr = ts.newVCR(k7Name, actionKeepCassette)
vcr.SetLiveOnlyMode()
vcr.SetRequestMatcher(govcr.NewBlankRequestMatcher()) // ensure always matching

Expand All @@ -199,7 +199,7 @@ func (ts *GoVCRTestSuite) TestVCR_OfflineMode() {
const k7Name = "temp-fixtures/TestGoVCRTestSuite.TestVCR_OfflineMode.cassette.json"

// 1st execution of set of calls - populate cassette
vcr := ts.loadCassette(k7Name, actionDelete)
vcr := ts.newVCR(k7Name, actionDeleteCassette)
vcr.SetRequestMatcher(govcr.NewBlankRequestMatcher()) // ensure always matching
vcr.SetNormalMode() // get data in the cassette

Expand All @@ -214,7 +214,7 @@ func (ts *GoVCRTestSuite) TestVCR_OfflineMode() {
ts.Require().FileExists(k7Name)

// 2nd execution of set of calls -- offline only
vcr = ts.loadCassette(k7Name, actionKeep)
vcr = ts.newVCR(k7Name, actionKeepCassette)
vcr.SetOfflineMode()

ts.makeHTTPCalls_WithSuccess(vcr.HTTPClient(), 0)
Expand Down Expand Up @@ -272,7 +272,7 @@ func (ts *GoVCRTestSuite) TestRoundTrip_ReplaysError() {
cassetteName := k7Name + fmt.Sprintf(".test_case_%d", idx)

// execute HTTP call and record on cassette
vcr := ts.loadCassette(cassetteName, actionDelete)
vcr := ts.newVCR(cassetteName, actionDeleteCassette)

resp, err := vcr.HTTPClient().Get(tc.reqURL) //nolint: bodyclose
ts.Require().Error(err)
Expand All @@ -289,7 +289,7 @@ func (ts *GoVCRTestSuite) TestRoundTrip_ReplaysError() {

// replay from cassette
ts.Require().FileExists(cassetteName)
vcr = ts.loadCassette(cassetteName, actionKeep)
vcr = ts.newVCR(cassetteName, actionKeepCassette)
ts.EqualValues(1, vcr.NumberOfTracks())

resp, err = vcr.HTTPClient().Get(tc.reqURL) //nolint: bodyclose
Expand All @@ -312,7 +312,7 @@ func (ts *GoVCRTestSuite) TestRoundTrip_ReplaysPlainResponse() {
const k7Name = "temp-fixtures/TestGoVCRTestSuite.TestRoundTrip_ReplaysPlainResponse.cassette.json"

// 1st execution of set of calls
vcr := ts.loadCassette(k7Name, actionDelete)
vcr := ts.newVCR(k7Name, actionDeleteCassette)

ts.makeHTTPCalls_WithSuccess(vcr.HTTPClient(), 0)
expectedStats := &stats.Stats{
Expand All @@ -325,7 +325,7 @@ func (ts *GoVCRTestSuite) TestRoundTrip_ReplaysPlainResponse() {
ts.Require().FileExists(k7Name)

// 2nd execution of set of calls (replayed with cassette reload)
vcr = ts.loadCassette(k7Name, actionKeep)
vcr = ts.newVCR(k7Name, actionKeepCassette)

ts.makeHTTPCalls_WithSuccess(vcr.HTTPClient(), 0)
expectedStats = &stats.Stats{
Expand Down
22 changes: 11 additions & 11 deletions govcr_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func (ts *GoVCRWBTestSuite) TearDownTest() {
type action int

const (
actionKeep = iota
actionDelete
actionKeepCassette = iota
actionDeleteCassette
)

func (ts *GoVCRWBTestSuite) loadCassette(cassetteName string, a action) *ControlPanel {
if a == actionDelete {
func (ts *GoVCRWBTestSuite) newVCR(cassetteName string, a action) *ControlPanel {
if a == actionDeleteCassette {
_ = os.Remove(cassetteName)
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_RequestMatcherDoesNotMutateState() {
}

// 1st call - live
vcr := ts.loadCassette(cassetteName, actionDelete)
vcr := ts.newVCR(cassetteName, actionDeleteCassette)
vcr.SetLiveOnlyMode() // ensure we record one track so we can have a request matcher execution later (no track on cassette = no request matching)
vcr.SetRequestMatcher(reqMatcher(false)) // false: we want to attempt but not satisfy request matching so to check if the live request was altered

Expand Down Expand Up @@ -135,7 +135,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_RequestMatcherDoesNotMutateState() {
vcrResp.Body = nil

// 2nd call - live
vcr = ts.loadCassette(cassetteName, actionKeep)
vcr = ts.newVCR(cassetteName, actionKeepCassette)
vcr.SetNormalMode() // ensure we attempt request matching
vcr.SetRequestMatcher(reqMatcher(false)) // false: we want to attempt but not satisfy request matching so to check if the live request was altered

Expand Down Expand Up @@ -166,7 +166,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_RequestMatcherDoesNotMutateState() {
ts.Require().EqualValues(vcrResp, vcrResp2)

// 3rd call - replayed
vcr = ts.loadCassette(cassetteName, actionKeep)
vcr = ts.newVCR(cassetteName, actionKeepCassette)
vcr.SetOfflineMode()

requestMatcherCount = 0
Expand Down Expand Up @@ -206,7 +206,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_WithRecordingAndReplayingMutations() {
const cassetteName = "temp-fixtures/TestRoundTrip_WithRecordingAndReplayingMutations.cassette.json"

// 1st execution of set of calls
vcr := ts.loadCassette(cassetteName, actionDelete)
vcr := ts.newVCR(cassetteName, actionDeleteCassette)
vcr.SetRecordingMutators(trackMutator)

ts.makeHTTPCalls_WithSuccess(vcr.HTTPClient())
Expand All @@ -219,7 +219,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_WithRecordingAndReplayingMutations() {
ts.Require().EqualValues(expectedStats, vcr.Stats())

// load the cassette and verify contents has been mutated.
vcr = ts.loadCassette(cassetteName, actionKeep)
vcr = ts.newVCR(cassetteName, actionKeepCassette)
vcr.SetRecordingMutators(trackMutator)

// note: remember that it usually doesn't make sense to modify the request in the replaying track mutator
Expand Down Expand Up @@ -250,7 +250,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_SavesAndReplaysMutatedTracksToCassette
const cassetteName = "temp-fixtures/TestRoundTrip_SavesAndReplaysMutatedTracksToCassette.cassette.json"

// 1st execution of set of calls
vcr := ts.loadCassette(cassetteName, actionDelete)
vcr := ts.newVCR(cassetteName, actionDeleteCassette)
vcr.SetRecordingMutators(trackMutator)

ts.makeHTTPCalls_WithSuccess(vcr.HTTPClient())
Expand All @@ -263,7 +263,7 @@ func (ts *GoVCRWBTestSuite) TestRoundTrip_SavesAndReplaysMutatedTracksToCassette
ts.Require().EqualValues(expectedStats, vcr.Stats())

// load the cassette and verify contents has been mutated.
vcr = ts.loadCassette(cassetteName, actionKeep)
vcr = ts.newVCR(cassetteName, actionKeepCassette)
vcr.SetRecordingMutators(trackMutator)

tracks := vcr.vcrTransport().cassette.Tracks
Expand Down

0 comments on commit af90e26

Please sign in to comment.