forked from cloudfoundry/auctioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_client_test.go
61 lines (48 loc) · 1.63 KB
/
service_client_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 auctioneer_test
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pivotal-golang/lager/lagertest"
"github.com/tedsuo/ifrit"
"github.com/tedsuo/ifrit/ginkgomon"
"github.com/cloudfoundry-incubator/auctioneer"
"github.com/pivotal-golang/clock/fakeclock"
)
var _ = Describe("ServiceClient", func() {
var serviceClient auctioneer.ServiceClient
var clock *fakeclock.FakeClock
var logger *lagertest.TestLogger
BeforeEach(func() {
clock = fakeclock.NewFakeClock(time.Now())
logger = lagertest.NewTestLogger("test")
consulClient := consulRunner.NewClient()
serviceClient = auctioneer.NewServiceClient(consulClient, clock)
})
Describe("AuctioneerAddress", func() {
Context("when able to get an auctioneer presence", func() {
var heartbeater ifrit.Process
var presence auctioneer.Presence
BeforeEach(func() {
presence = auctioneer.NewPresence("auctioneer-id", "auctioneer.example.com")
auctioneerLock, err := serviceClient.NewAuctioneerLockRunner(logger, presence, 100*time.Millisecond, 10*time.Second)
Expect(err).NotTo(HaveOccurred())
heartbeater = ginkgomon.Invoke(auctioneerLock)
})
AfterEach(func() {
ginkgomon.Interrupt(heartbeater)
})
It("returns the address", func() {
address, err := serviceClient.CurrentAuctioneerAddress()
Expect(err).NotTo(HaveOccurred())
Expect(address).To(Equal(presence.AuctioneerAddress))
})
})
Context("when unable to get any auctioneer presences", func() {
It("returns ErrServiceUnavailable", func() {
_, err := serviceClient.CurrentAuctioneerAddress()
Expect(err).To(HaveOccurred())
})
})
})
})