forked from autogrow/wray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_factory_test.go
More file actions
47 lines (37 loc) · 1.09 KB
/
client_factory_test.go
File metadata and controls
47 lines (37 loc) · 1.09 KB
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
package wray
import (
"sync"
"time"
)
type FakeSchedular struct {
requestedDelay time.Duration
}
func (fs *FakeSchedular) wait(delay time.Duration, callback func()) {
fs.requestedDelay = delay
}
func (fs *FakeSchedular) delay() time.Duration {
return fs.requestedDelay
}
type FayeClientBuilder struct {
client FayeClient
}
func BuildFayeClient() FayeClientBuilder {
schedular := &FakeSchedular{}
client := FayeClient{state: UNCONNECTED, url: "https://localhost", clientID: "", schedular: schedular, mutex: &sync.RWMutex{}, connectMutex: &sync.RWMutex{}}
return FayeClientBuilder{client}
}
func (factory FayeClientBuilder) Client() FayeClient {
return factory.client
}
func (factory FayeClientBuilder) Connected() FayeClientBuilder {
factory.client.state = CONNECTED
return factory
}
func (factory FayeClientBuilder) WithTransport(transport Transport) FayeClientBuilder {
factory.client.transport = transport
return factory
}
func (factory FayeClientBuilder) WithSubscriptions(subscriptions []*Subscription) FayeClientBuilder {
factory.client.subscriptions = subscriptions
return factory
}