Skip to content

Commit

Permalink
feat: allow interactions to be replayed
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdalmeida committed Nov 5, 2020
1 parent 82c7a03 commit 178042c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ _testmain.go

# Ignore test code coverage
coverage.txt

.idea/
4 changes: 3 additions & 1 deletion cassette/cassette.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type Cassette struct {
Mu sync.RWMutex `yaml:"mu,omitempty"`
// Interactions between client and server
Interactions []*Interaction `yaml:"interactions"`
// ReplayableInteractions defines whether to allow interactions to be replayed or not
ReplayableInteractions bool `yaml:"-"`

// Matches actual request with interaction requests.
Matcher Matcher `yaml:"-"`
Expand Down Expand Up @@ -176,7 +178,7 @@ func (c *Cassette) GetInteraction(r *http.Request) (*Interaction, error) {
c.Mu.Lock()
defer c.Mu.Unlock()
for _, i := range c.Interactions {
if !i.replayed && c.Matcher(r, i.Request) {
if (c.ReplayableInteractions || !i.replayed) && c.Matcher(r, i.Request) {
i.replayed = true
return i, nil
}
Expand Down
7 changes: 7 additions & 0 deletions recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ func (r *Recorder) SetMatcher(matcher cassette.Matcher) {
}
}

// SetReplayableInteractions defines whether to allow interactions to be replayed or not.
func (r *Recorder) SetReplayableInteractions(replayable bool) {
if r.cassette != nil {
r.cassette.ReplayableInteractions = replayable
}
}

// AddPassthrough appends a hook to determine if a request should be ignored by the
// recorder.
func (r *Recorder) AddPassthrough(pass Passthrough) {
Expand Down

0 comments on commit 178042c

Please sign in to comment.