NowPlaying is not a repo, now it is part of the main engine

This commit is contained in:
Deluan
2020-01-18 20:21:25 -05:00
parent 128e165aba
commit 3c66da0b17
11 changed files with 168 additions and 178 deletions
+49
View File
@@ -0,0 +1,49 @@
package engine
import (
"sync"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("NowPlayingRepository", func() {
var repo NowPlayingRepository
BeforeEach(func() {
playerMap = sync.Map{}
repo = NewNowPlayingRepository()
})
It("enqueues and dequeues records", func() {
Expect(repo.Enqueue(&NowPlayingInfo{PlayerId: 1, TrackID: "AAA"})).To(BeNil())
Expect(repo.Enqueue(&NowPlayingInfo{PlayerId: 1, TrackID: "BBB"})).To(BeNil())
Expect(repo.Tail(1)).To(Equal(&NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
Expect(repo.Head(1)).To(Equal(&NowPlayingInfo{PlayerId: 1, TrackID: "BBB"}))
Expect(repo.Count(1)).To(Equal(int64(2)))
Expect(repo.Dequeue(1)).To(Equal(&NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
Expect(repo.Count(1)).To(Equal(int64(1)))
})
It("handles multiple players", func() {
Expect(repo.Enqueue(&NowPlayingInfo{PlayerId: 1, TrackID: "AAA"})).To(BeNil())
Expect(repo.Enqueue(&NowPlayingInfo{PlayerId: 1, TrackID: "BBB"})).To(BeNil())
Expect(repo.Enqueue(&NowPlayingInfo{PlayerId: 2, TrackID: "CCC"})).To(BeNil())
Expect(repo.Enqueue(&NowPlayingInfo{PlayerId: 2, TrackID: "DDD"})).To(BeNil())
Expect(repo.GetAll()).To(ConsistOf([]*NowPlayingInfo{
{PlayerId: 1, TrackID: "BBB"},
{PlayerId: 2, TrackID: "DDD"},
}))
Expect(repo.Count(2)).To(Equal(int64(2)))
Expect(repo.Count(2)).To(Equal(int64(2)))
Expect(repo.Tail(1)).To(Equal(&NowPlayingInfo{PlayerId: 1, TrackID: "AAA"}))
Expect(repo.Head(2)).To(Equal(&NowPlayingInfo{PlayerId: 2, TrackID: "DDD"}))
})
})