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