forked from navidrome/navidrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsse_test.go
61 lines (56 loc) · 1.66 KB
/
sse_test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package events
import (
"context"
"github.com/navidrome/navidrome/model/request"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Broker", func() {
var b broker
BeforeEach(func() {
b = broker{}
})
Describe("shouldSend", func() {
var c client
var ctx context.Context
BeforeEach(func() {
ctx = context.Background()
c = client{
clientUniqueId: "1111",
username: "janedoe",
}
})
Context("request has clientUniqueId", func() {
It("sends message for same username, different clientUniqueId", func() {
ctx = request.WithClientUniqueId(ctx, "2222")
ctx = request.WithUsername(ctx, "janedoe")
m := message{senderCtx: ctx}
Expect(b.shouldSend(m, c)).To(BeTrue())
})
It("does not send message for same username, same clientUniqueId", func() {
ctx = request.WithClientUniqueId(ctx, "1111")
ctx = request.WithUsername(ctx, "janedoe")
m := message{senderCtx: ctx}
Expect(b.shouldSend(m, c)).To(BeFalse())
})
It("does not send message for different username", func() {
ctx = request.WithClientUniqueId(ctx, "3333")
ctx = request.WithUsername(ctx, "johndoe")
m := message{senderCtx: ctx}
Expect(b.shouldSend(m, c)).To(BeFalse())
})
})
Context("request does not have clientUniqueId", func() {
It("sends message for same username", func() {
ctx = request.WithUsername(ctx, "janedoe")
m := message{senderCtx: ctx}
Expect(b.shouldSend(m, c)).To(BeTrue())
})
It("sends message for different username", func() {
ctx = request.WithUsername(ctx, "johndoe")
m := message{senderCtx: ctx}
Expect(b.shouldSend(m, c)).To(BeTrue())
})
})
})
})