-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_test.go
58 lines (47 loc) · 1.34 KB
/
init_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
package main_test
import (
"sync"
"testing"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/sclevine/agouti"
)
func TestRockPaperScissors(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Integration Suite")
}
var agoutiDriver *agouti.WebDriver
var pathToServer string
var _ = SynchronizedBeforeSuite(func() []byte {
pathToServer, err := gexec.Build("github.com/desmondrawls/rock-paper-scissors")
Expect(err).NotTo(HaveOccurred())
return []byte(pathToServer)
}, func(data []byte) {
pathToServer = string(data)
agoutiDriver = agouti.PhantomJS()
Expect(agoutiDriver.Start()).To(Succeed())
})
var _ = SynchronizedAfterSuite(func() {
Expect(agoutiDriver.Stop()).To(Succeed())
gexec.CleanupBuildArtifacts()
}, func() {})
var (
lastPortUsed int
mutex sync.Mutex
once sync.Once
)
// PickAPort returns a port that is likely free for use in a Ginkgo test
func PickAPort() int {
mutex.Lock()
defer mutex.Unlock()
if lastPortUsed == 0 {
once.Do(func() {
const portRangeStart = 61000
lastPortUsed = portRangeStart + config.GinkgoConfig.ParallelNode
})
}
lastPortUsed += config.GinkgoConfig.ParallelTotal
return lastPortUsed
}