1- package listener_test
1+ package pgwatcher_test
22
33import (
44 "context"
55 "errors"
6- "listener "
6+ "github.com/smarter-day/pgwatcher "
77 "sync"
88 "testing"
99 "time"
@@ -16,13 +16,13 @@ type mockListener struct {
1616 mu sync.Mutex
1717 connected bool
1818 channels map [string ]bool
19- notificationsC chan * listener .Notification
19+ notificationsC chan * pgwatcher .Notification
2020}
2121
2222func newMockListener () * mockListener {
2323 return & mockListener {
2424 channels : make (map [string ]bool ),
25- notificationsC : make (chan * listener .Notification , 100 ),
25+ notificationsC : make (chan * pgwatcher .Notification , 100 ),
2626 }
2727}
2828
@@ -58,7 +58,7 @@ func (m *mockListener) UnListen(ctx context.Context, channel string) error {
5858 return nil
5959}
6060
61- func (m * mockListener ) WaitForNotification (ctx context.Context ) (* listener .Notification , error ) {
61+ func (m * mockListener ) WaitForNotification (ctx context.Context ) (* pgwatcher .Notification , error ) {
6262 select {
6363 case <- ctx .Done ():
6464 return nil , ctx .Err ()
@@ -80,7 +80,7 @@ func (m *mockListener) Ping(ctx context.Context) error {
8080}
8181
8282// pushNotification simulates server pushing a notification.
83- func (m * mockListener ) pushNotification (ntf * listener .Notification ) {
83+ func (m * mockListener ) pushNotification (ntf * pgwatcher .Notification ) {
8484 m .notificationsC <- ntf
8585}
8686
@@ -94,7 +94,7 @@ func TestNotifierWithSingleChannel(t *testing.T) {
9494 defer cancel ()
9595
9696 mockL := newMockListener ()
97- n := listener .NewNotifier (mockL )
97+ n := pgwatcher .NewNotifier (mockL )
9898
9999 // Start the Notifier (it will Connect automatically in the runLoop).
100100 err := n .Run (ctx )
@@ -109,7 +109,7 @@ func TestNotifierWithSingleChannel(t *testing.T) {
109109 go func () {
110110 time .Sleep (200 * time .Millisecond ) // Let it set up
111111 for _ , w := range want {
112- mockL .pushNotification (& listener .Notification {
112+ mockL .pushNotification (& pgwatcher .Notification {
113113 Channel : "foo" ,
114114 Payload : []byte (w ),
115115 })
@@ -141,7 +141,7 @@ func TestNotifierWithMultipleChannels(t *testing.T) {
141141 defer cancel ()
142142
143143 mockL := newMockListener ()
144- n := listener .NewNotifier (mockL )
144+ n := pgwatcher .NewNotifier (mockL )
145145 err := n .Run (ctx )
146146 is .NoErr (err )
147147
@@ -152,10 +152,10 @@ func TestNotifierWithMultipleChannels(t *testing.T) {
152152 // We want to ensure concurrency across channels, so we push them at the same time.
153153 go func () {
154154 time .Sleep (200 * time .Millisecond )
155- mockL .pushNotification (& listener .Notification {Channel : "foo" , Payload : []byte ("foo1" )})
156- mockL .pushNotification (& listener .Notification {Channel : "bar" , Payload : []byte ("bar1" )})
157- mockL .pushNotification (& listener .Notification {Channel : "foo" , Payload : []byte ("foo2" )})
158- mockL .pushNotification (& listener .Notification {Channel : "bar" , Payload : []byte ("bar2" )})
155+ mockL .pushNotification (& pgwatcher .Notification {Channel : "foo" , Payload : []byte ("foo1" )})
156+ mockL .pushNotification (& pgwatcher .Notification {Channel : "bar" , Payload : []byte ("bar1" )})
157+ mockL .pushNotification (& pgwatcher .Notification {Channel : "foo" , Payload : []byte ("foo2" )})
158+ mockL .pushNotification (& pgwatcher .Notification {Channel : "bar" , Payload : []byte ("bar2" )})
159159 }()
160160
161161 var gotFoo , gotBar []string
0 commit comments