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