/
recorder.go
38 lines (30 loc) · 946 Bytes
/
recorder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package testutils
import "github.com/CyCoreSystems/ari/v5"
// A RecorderPair is the pair of results returned from a mock Record request
type RecorderPair struct {
Handle *ari.LiveRecordingHandle
Err error
}
// Recorder is the test player that can be primed with sample data
type Recorder struct {
Next chan struct{}
results []RecorderPair
}
// NewRecorder creates a new player
func NewRecorder() *Recorder {
return &Recorder{
Next: make(chan struct{}, 10),
}
}
// Append appends the given Play results
func (r *Recorder) Append(h *ari.LiveRecordingHandle, err error) {
r.results = append(r.results, RecorderPair{h, err})
}
// Record pops the top results and returns them, as well as triggering player.Next
func (r *Recorder) Record(name string, opts *ari.RecordingOptions) (h *ari.LiveRecordingHandle, err error) {
h = r.results[0].Handle
err = r.results[0].Err
r.results = r.results[1:]
r.Next <- struct{}{}
return
}