forked from cloudfoundry/consuladapter
/
consuladapter_suite_test.go
65 lines (53 loc) · 1.68 KB
/
consuladapter_suite_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
62
63
64
65
package consuladapter_test
import (
"fmt"
"github.com/cloudfoundry-incubator/consuladapter"
"github.com/cloudfoundry-incubator/consuladapter/consulrunner"
"github.com/cloudfoundry-incubator/consuladapter/fakes"
"github.com/hashicorp/consul/api"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
. "github.com/onsi/gomega"
"testing"
)
func TestConsulAdapter(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Adapter <-> Cluster-Runner Integration Suite")
}
const clusterSize = 1
var clusterRunner *consulrunner.ClusterRunner
var session *consuladapter.Session
var _ = BeforeSuite(func() {
clusterStartingPort := 5001 + config.GinkgoConfig.ParallelNode*consulrunner.PortOffsetLength*clusterSize
clusterRunner = consulrunner.NewClusterRunner(clusterStartingPort, clusterSize, "http")
})
func stopCluster() {
clusterRunner.Stop()
}
func stopClusterAndSession() {
if session != nil {
session.Destroy()
}
stopCluster()
}
func startClusterAndSession() {
startCluster()
session = clusterRunner.NewSession(fmt.Sprintf("session-%d", config.GinkgoConfig.ParallelNode))
}
func startCluster() {
clusterRunner.Start()
clusterRunner.WaitUntilReady()
}
func newFakeSessionManager(client *api.Client) *fakes.FakeSessionManager {
sessionMgr := &fakes.FakeSessionManager{}
realSM := consuladapter.NewSessionManager(client)
sessionMgr.NodeNameStub = realSM.NodeName
sessionMgr.NodeStub = realSM.Node
sessionMgr.CreateStub = realSM.Create
sessionMgr.CreateNoChecksStub = realSM.CreateNoChecks
sessionMgr.DestroyStub = realSM.Destroy
sessionMgr.RenewStub = realSM.Renew
sessionMgr.RenewPeriodicStub = realSM.RenewPeriodic
sessionMgr.NewLockStub = realSM.NewLock
return sessionMgr
}