Move logic back into fixtures constructor

- Introduce a type for the fixture process configuration
This commit is contained in:
Hannes Hörl 2017-12-06 12:15:38 +00:00 committed by Gareth Smith
parent 15d507fc83
commit 819ad8519f
10 changed files with 133 additions and 218 deletions

View File

@ -18,6 +18,7 @@ type APIServer struct {
Path string Path string
ProcessStarter simpleSessionStarter ProcessStarter simpleSessionStarter
CertDirManager certDirManager CertDirManager certDirManager
Config *APIServerConfig
session SimpleSession session SimpleSession
stdOut *gbytes.Buffer stdOut *gbytes.Buffer
stdErr *gbytes.Buffer stdErr *gbytes.Buffer
@ -28,10 +29,16 @@ type certDirManager interface {
Destroy() error Destroy() error
} }
// APIServerConfig is a struct holding data to configure the API Server process
type APIServerConfig struct {
EtcdURL string
APIServerURL string
}
//go:generate counterfeiter . certDirManager //go:generate counterfeiter . certDirManager
// NewAPIServer creates a new APIServer Fixture Process // NewAPIServer creates a new APIServer Fixture Process
func NewAPIServer(pathToAPIServer string) *APIServer { func NewAPIServer(pathToAPIServer string, config *APIServerConfig) *APIServer {
starter := func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) { starter := func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) {
return gexec.Start(command, out, err) return gexec.Start(command, out, err)
} }
@ -40,13 +47,14 @@ func NewAPIServer(pathToAPIServer string) *APIServer {
Path: pathToAPIServer, Path: pathToAPIServer,
ProcessStarter: starter, ProcessStarter: starter,
CertDirManager: NewTempDirManager(), CertDirManager: NewTempDirManager(),
Config: config,
} }
return apiserver return apiserver
} }
// Start starts the apiserver, waits for it to come up, and returns an error, if occoured. // Start starts the apiserver, waits for it to come up, and returns an error, if occoured.
func (s *APIServer) Start(config map[string]string) error { func (s *APIServer) Start() error {
s.stdOut = gbytes.NewBuffer() s.stdOut = gbytes.NewBuffer()
s.stdErr = gbytes.NewBuffer() s.stdErr = gbytes.NewBuffer()
@ -55,16 +63,7 @@ func (s *APIServer) Start(config map[string]string) error {
return err return err
} }
etcdURL, ok := config["etcdURL"] clientURL, err := url.Parse(s.Config.APIServerURL)
if !ok {
return fmt.Errorf("config setting 'etcdURL' not found")
}
apiServerURL, ok := config["apiServerURL"]
if !ok {
return fmt.Errorf("config setting 'apiServerURL' not found")
}
url, err := url.Parse(apiServerURL)
if err != nil { if err != nil {
return err return err
} }
@ -77,13 +76,13 @@ func (s *APIServer) Start(config map[string]string) error {
"--admission-control-config-file=", "--admission-control-config-file=",
"--bind-address=0.0.0.0", "--bind-address=0.0.0.0",
"--storage-backend=etcd3", "--storage-backend=etcd3",
fmt.Sprintf("--etcd-servers=%s", etcdURL), fmt.Sprintf("--etcd-servers=%s", s.Config.EtcdURL),
fmt.Sprintf("--cert-dir=%s", certDir), fmt.Sprintf("--cert-dir=%s", certDir),
fmt.Sprintf("--insecure-port=%s", url.Port()), fmt.Sprintf("--insecure-port=%s", clientURL.Port()),
fmt.Sprintf("--insecure-bind-address=%s", url.Hostname()), fmt.Sprintf("--insecure-bind-address=%s", clientURL.Hostname()),
} }
detectedStart := s.stdErr.Detect(fmt.Sprintf("Serving insecurely on %s", url.Host)) detectedStart := s.stdErr.Detect(fmt.Sprintf("Serving insecurely on %s", clientURL.Host))
timedOut := time.After(20 * time.Second) timedOut := time.After(20 * time.Second)
command := exec.Command(s.Path, args...) command := exec.Command(s.Path, args...)

View File

@ -20,21 +20,21 @@ var _ = Describe("Apiserver", func() {
fakeSession *testfakes.FakeSimpleSession fakeSession *testfakes.FakeSimpleSession
fakeCertDirManager *testfakes.FakeCertDirManager fakeCertDirManager *testfakes.FakeCertDirManager
apiServer *APIServer apiServer *APIServer
apiServerConfig map[string]string apiServerConfig *APIServerConfig
) )
BeforeEach(func() { BeforeEach(func() {
fakeSession = &testfakes.FakeSimpleSession{} fakeSession = &testfakes.FakeSimpleSession{}
fakeCertDirManager = &testfakes.FakeCertDirManager{} fakeCertDirManager = &testfakes.FakeCertDirManager{}
apiServerConfig = &APIServerConfig{
EtcdURL: "http://this.is.etcd:2345/",
APIServerURL: "http://this.is.the.API.server:8080",
}
apiServer = &APIServer{ apiServer = &APIServer{
Path: "", Path: "",
CertDirManager: fakeCertDirManager, CertDirManager: fakeCertDirManager,
} Config: apiServerConfig,
apiServerConfig = map[string]string{
"apiServerURL": "http://this.is.the.API.server:8080",
"etcdURL": "http://this.is.etcd:2345/",
} }
}) })
@ -53,7 +53,7 @@ var _ = Describe("Apiserver", func() {
} }
By("Starting the API Server") By("Starting the API Server")
err := apiServer.Start(apiServerConfig) err := apiServer.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Eventually(apiServer).Should(gbytes.Say("Everything is fine")) Eventually(apiServer).Should(gbytes.Say("Everything is fine"))
@ -82,7 +82,7 @@ var _ = Describe("Apiserver", func() {
return fakeSession, nil return fakeSession, nil
} }
err := apiServer.Start(apiServerConfig) err := apiServer.Start()
Expect(err).To(MatchError(ContainSubstring("Error on cert directory creation."))) Expect(err).To(MatchError(ContainSubstring("Error on cert directory creation.")))
Expect(processStarterCounter).To(Equal(0)) Expect(processStarterCounter).To(Equal(0))
}) })
@ -94,7 +94,7 @@ var _ = Describe("Apiserver", func() {
return nil, fmt.Errorf("Some error in the apiserver starter.") return nil, fmt.Errorf("Some error in the apiserver starter.")
} }
err := apiServer.Start(apiServerConfig) err := apiServer.Start()
Expect(err).To(MatchError(ContainSubstring("Some error in the apiserver starter."))) Expect(err).To(MatchError(ContainSubstring("Some error in the apiserver starter.")))
}) })
}) })

View File

@ -44,7 +44,9 @@ var _ = BeforeSuite(func() {
Expect(pathToEtcd).NotTo(BeEmpty(), "Path to etcd cannot be empty, set $TEST_ETCD_BIN") Expect(pathToEtcd).NotTo(BeEmpty(), "Path to etcd cannot be empty, set $TEST_ETCD_BIN")
Expect(pathToAPIServer).NotTo(BeEmpty(), "Path to apiserver cannot be empty, set $TEST_APISERVER_BIN") Expect(pathToAPIServer).NotTo(BeEmpty(), "Path to apiserver cannot be empty, set $TEST_APISERVER_BIN")
fixtures = test.NewFixtures(pathToEtcd, pathToAPIServer) fixtures, err = test.NewFixtures(pathToEtcd, pathToAPIServer)
Expect(err).NotTo(HaveOccurred())
err = fixtures.Start() err = fixtures.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })

View File

@ -18,6 +18,7 @@ type Etcd struct {
Path string Path string
ProcessStarter simpleSessionStarter ProcessStarter simpleSessionStarter
DataDirManager dataDirManager DataDirManager dataDirManager
Config *EtcdConfig
session SimpleSession session SimpleSession
stdOut *gbytes.Buffer stdOut *gbytes.Buffer
stdErr *gbytes.Buffer stdErr *gbytes.Buffer
@ -28,6 +29,12 @@ type dataDirManager interface {
Destroy() error Destroy() error
} }
// EtcdConfig is a struct holding data to configure the Etcd process
type EtcdConfig struct {
ClientURL string
PeerURL string
}
//go:generate counterfeiter . dataDirManager //go:generate counterfeiter . dataDirManager
// SimpleSession describes a CLI session. You can get output, and you can kill it. It is implemented by *gexec.Session. // SimpleSession describes a CLI session. You can get output, and you can kill it. It is implemented by *gexec.Session.
@ -43,7 +50,7 @@ type SimpleSession interface {
type simpleSessionStarter func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) type simpleSessionStarter func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error)
// NewEtcd constructs an Etcd Fixture Process // NewEtcd constructs an Etcd Fixture Process
func NewEtcd(pathToEtcd string) *Etcd { func NewEtcd(pathToEtcd string, config *EtcdConfig) *Etcd {
starter := func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) { starter := func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) {
return gexec.Start(command, out, err) return gexec.Start(command, out, err)
} }
@ -52,13 +59,14 @@ func NewEtcd(pathToEtcd string) *Etcd {
Path: pathToEtcd, Path: pathToEtcd,
ProcessStarter: starter, ProcessStarter: starter,
DataDirManager: NewTempDirManager(), DataDirManager: NewTempDirManager(),
Config: config,
} }
return etcd return etcd
} }
// Start starts the etcd, waits for it to come up, and returns an error, if occoured. // Start starts the etcd, waits for it to come up, and returns an error, if occoured.
func (e *Etcd) Start(config map[string]string) error { func (e *Etcd) Start() error {
e.stdOut = gbytes.NewBuffer() e.stdOut = gbytes.NewBuffer()
e.stdErr = gbytes.NewBuffer() e.stdErr = gbytes.NewBuffer()
@ -67,34 +75,25 @@ func (e *Etcd) Start(config map[string]string) error {
return err return err
} }
clientURL, ok := config["clientURL"]
if !ok {
return fmt.Errorf("config setting 'clientURL' not found")
}
peerURL, ok := config["peerURL"]
if !ok {
return fmt.Errorf("config setting 'peerURL' not found")
}
args := []string{ args := []string{
"--debug", "--debug",
"--advertise-client-urls", "--advertise-client-urls",
clientURL, e.Config.ClientURL,
"--listen-client-urls", "--listen-client-urls",
clientURL, e.Config.ClientURL,
"--listen-peer-urls", "--listen-peer-urls",
peerURL, e.Config.PeerURL,
"--data-dir", "--data-dir",
dataDir, dataDir,
} }
url, err := url.Parse(clientURL) clientURL, err := url.Parse(e.Config.ClientURL)
if err != nil { if err != nil {
return err return err
} }
detectedStart := e.stdErr.Detect(fmt.Sprintf( detectedStart := e.stdErr.Detect(fmt.Sprintf(
"serving insecure client requests on %s", url.Host)) "serving insecure client requests on %s", clientURL.Host))
timedOut := time.After(20 * time.Second) timedOut := time.After(20 * time.Second)
command := exec.Command(e.Path, args...) command := exec.Command(e.Path, args...)

View File

@ -20,21 +20,22 @@ var _ = Describe("Etcd", func() {
fakeSession *testfakes.FakeSimpleSession fakeSession *testfakes.FakeSimpleSession
fakeDataDirManager *testfakes.FakeDataDirManager fakeDataDirManager *testfakes.FakeDataDirManager
etcd *Etcd etcd *Etcd
etcdConfig map[string]string etcdConfig *EtcdConfig
) )
BeforeEach(func() { BeforeEach(func() {
fakeSession = &testfakes.FakeSimpleSession{} fakeSession = &testfakes.FakeSimpleSession{}
fakeDataDirManager = &testfakes.FakeDataDirManager{} fakeDataDirManager = &testfakes.FakeDataDirManager{}
etcdConfig = &EtcdConfig{
ClientURL: "http://this.is.etcd.listening.for.clients:1234",
PeerURL: "http://this.is.etcd.listening.for.peers:1235",
}
etcd = &Etcd{ etcd = &Etcd{
Path: "", Path: "",
DataDirManager: fakeDataDirManager, DataDirManager: fakeDataDirManager,
} Config: etcdConfig,
etcdConfig = map[string]string{
"clientURL": "http://this.is.etcd.listening.for.clients:1234",
"peerURL": "http://this.is.etcd.listening.for.peers:1235",
} }
}) })
@ -53,7 +54,7 @@ var _ = Describe("Etcd", func() {
} }
By("Starting the Etcd Server") By("Starting the Etcd Server")
err := etcd.Start(etcdConfig) err := etcd.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Eventually(etcd).Should(gbytes.Say("Everything is dandy")) Eventually(etcd).Should(gbytes.Say("Everything is dandy"))
@ -82,7 +83,7 @@ var _ = Describe("Etcd", func() {
return fakeSession, nil return fakeSession, nil
} }
err := etcd.Start(etcdConfig) err := etcd.Start()
Expect(err).To(MatchError(ContainSubstring("Error on directory creation."))) Expect(err).To(MatchError(ContainSubstring("Error on directory creation.")))
Expect(processStarterCounter).To(Equal(0)) Expect(processStarterCounter).To(Equal(0))
}) })
@ -94,7 +95,7 @@ var _ = Describe("Etcd", func() {
return nil, fmt.Errorf("Some error in the starter.") return nil, fmt.Errorf("Some error in the starter.")
} }
err := etcd.Start(etcdConfig) err := etcd.Start()
Expect(err).To(MatchError(ContainSubstring("Some error in the starter."))) Expect(err).To(MatchError(ContainSubstring("Some error in the starter.")))
}) })
}) })

View File

@ -12,7 +12,6 @@ type Fixtures struct {
Etcd FixtureProcess Etcd FixtureProcess
APIServer FixtureProcess APIServer FixtureProcess
Config FixturesConfig Config FixturesConfig
URLGetter listenURLGetter
} }
// FixturesConfig is a datastructure that exposes configuration that should be used by clients to talk // FixturesConfig is a datastructure that exposes configuration that should be used by clients to talk
@ -25,60 +24,61 @@ type FixturesConfig struct {
// This interface is potentially going to be expanded to e.g. allow access to the processes StdOut/StdErr // This interface is potentially going to be expanded to e.g. allow access to the processes StdOut/StdErr
// and other internals. // and other internals.
type FixtureProcess interface { type FixtureProcess interface {
Start(config map[string]string) error Start() error
Stop() Stop()
} }
//go:generate counterfeiter . FixtureProcess //go:generate counterfeiter . FixtureProcess
// NewFixtures will give you a Fixtures struct that's properly wired together. // NewFixtures will give you a Fixtures struct that's properly wired together.
func NewFixtures(pathToEtcd, pathToAPIServer string) *Fixtures { func NewFixtures(pathToEtcd, pathToAPIServer string) (*Fixtures, error) {
fixtures := &Fixtures{ etcdConfig := &EtcdConfig{}
Etcd: NewEtcd(pathToEtcd), apiServerConfig := &APIServerConfig{}
APIServer: NewAPIServer(pathToAPIServer),
URLGetter: getHTTPListenURL, if url, err := getHTTPListenURL(); err == nil {
etcdConfig.ClientURL = url
apiServerConfig.EtcdURL = url
} else {
return nil, err
} }
return fixtures if url, err := getHTTPListenURL(); err == nil {
etcdConfig.PeerURL = url
} else {
return nil, err
}
if url, err := getHTTPListenURL(); err == nil {
apiServerConfig.APIServerURL = url
} else {
return nil, err
}
fixtures := &Fixtures{
Etcd: NewEtcd(pathToEtcd, etcdConfig),
APIServer: NewAPIServer(pathToAPIServer, apiServerConfig),
}
fixtures.Config = FixturesConfig{
APIServerURL: apiServerConfig.APIServerURL,
}
return fixtures, nil
} }
// Start will start all your fixtures. To stop them, call Stop(). // Start will start all your fixtures. To stop them, call Stop().
func (f *Fixtures) Start() error { func (f *Fixtures) Start() error {
type configs map[string]string
etcdClientURL, err := f.URLGetter()
if err != nil {
return err
}
etcdPeerURL, err := f.URLGetter()
if err != nil {
return err
}
apiServerURL, err := f.URLGetter()
if err != nil {
return err
}
etcdConf := configs{
"peerURL": etcdPeerURL,
"clientURL": etcdClientURL,
}
apiServerConf := configs{
"etcdURL": etcdClientURL,
"apiServerURL": apiServerURL,
}
started := make(chan error) started := make(chan error)
starter := func(process FixtureProcess, conf configs) { starter := func(process FixtureProcess) {
started <- process.Start(conf) started <- process.Start()
} }
processes := map[FixtureProcess]configs{ processes := []FixtureProcess{
f.Etcd: etcdConf, f.Etcd,
f.APIServer: apiServerConf, f.APIServer,
} }
for process, config := range processes { for _, process := range processes {
go starter(process, config) go starter(process)
} }
for range processes { for range processes {
@ -87,10 +87,6 @@ func (f *Fixtures) Start() error {
} }
} }
f.Config = FixturesConfig{
APIServerURL: apiServerURL,
}
return nil return nil
} }
@ -101,10 +97,6 @@ func (f *Fixtures) Stop() error {
return nil return nil
} }
type listenURLGetter func() (url string, err error)
//go:generate counterfeiter . listenURLGetter
func getHTTPListenURL() (url string, err error) { func getHTTPListenURL() (url string, err error) {
host := "127.0.0.1" host := "127.0.0.1"
port, err := getFreePort(host) port, err := getFreePort(host)

View File

@ -12,7 +12,8 @@ import (
var _ = Describe("Fixtures", func() { var _ = Describe("Fixtures", func() {
It("can construct a properly wired Fixtures struct", func() { It("can construct a properly wired Fixtures struct", func() {
f := NewFixtures("path to etcd", "path to apiserver") f, err := NewFixtures("path to etcd", "path to apiserver")
Expect(err).NotTo(HaveOccurred())
Expect(f.Etcd.(*Etcd).Path).To(Equal("path to etcd")) Expect(f.Etcd.(*Etcd).Path).To(Equal("path to etcd"))
Expect(f.APIServer.(*APIServer).Path).To(Equal("path to apiserver")) Expect(f.APIServer.(*APIServer).Path).To(Equal("path to apiserver"))
}) })
@ -21,24 +22,20 @@ var _ = Describe("Fixtures", func() {
var ( var (
fakeEtcdProcess *testfakes.FakeFixtureProcess fakeEtcdProcess *testfakes.FakeFixtureProcess
fakeAPIServerProcess *testfakes.FakeFixtureProcess fakeAPIServerProcess *testfakes.FakeFixtureProcess
fakeListenURLGetter *testfakes.FakeListenURLGetter
fixtures Fixtures fixtures Fixtures
) )
BeforeEach(func() { BeforeEach(func() {
fakeEtcdProcess = &testfakes.FakeFixtureProcess{} fakeEtcdProcess = &testfakes.FakeFixtureProcess{}
fakeAPIServerProcess = &testfakes.FakeFixtureProcess{} fakeAPIServerProcess = &testfakes.FakeFixtureProcess{}
fakeListenURLGetter = &testfakes.FakeListenURLGetter{}
fixtures = Fixtures{ fixtures = Fixtures{
Etcd: fakeEtcdProcess, Etcd: fakeEtcdProcess,
APIServer: fakeAPIServerProcess, APIServer: fakeAPIServerProcess,
URLGetter: fakeListenURLGetter.Spy,
} }
}) })
It("can start them", func() { It("can start them", func() {
err := fixtures.Start() err := fixtures.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(fakeListenURLGetter.CallCount()).To(Equal(3))
By("starting Etcd") By("starting Etcd")
Expect(fakeEtcdProcess.StartCallCount()).To(Equal(1), Expect(fakeEtcdProcess.StartCallCount()).To(Equal(1),
@ -53,7 +50,6 @@ var _ = Describe("Fixtures", func() {
It("wraps the error", func() { It("wraps the error", func() {
fakeEtcdProcess.StartReturns(fmt.Errorf("some error")) fakeEtcdProcess.StartReturns(fmt.Errorf("some error"))
err := fixtures.Start() err := fixtures.Start()
Expect(fakeListenURLGetter.CallCount()).To(Equal(3))
Expect(err).To(MatchError(ContainSubstring("some error"))) Expect(err).To(MatchError(ContainSubstring("some error")))
}) })
}) })
@ -62,7 +58,6 @@ var _ = Describe("Fixtures", func() {
It("wraps the error", func() { It("wraps the error", func() {
fakeAPIServerProcess.StartReturns(fmt.Errorf("another error")) fakeAPIServerProcess.StartReturns(fmt.Errorf("another error"))
err := fixtures.Start() err := fixtures.Start()
Expect(fakeListenURLGetter.CallCount()).To(Equal(3))
Expect(err).To(MatchError(ContainSubstring("another error"))) Expect(err).To(MatchError(ContainSubstring("another error")))
}) })
}) })

View File

@ -14,17 +14,37 @@ import (
var _ = Describe("The Testing Framework", func() { var _ = Describe("The Testing Framework", func() {
It("Successfully manages the fixtures lifecycle", func() { It("Successfully manages the fixtures lifecycle", func() {
fixtures := test.NewFixtures(defaultPathToEtcd, defaultPathToApiserver) var err error
var fixtures *test.Fixtures
By("Starting all the fixture processes") fixtures, err = test.NewFixtures(defaultPathToEtcd, defaultPathToApiserver)
err := fixtures.Start()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to start successfully")
apiServerURL, err := url.Parse(fixtures.Config.APIServerURL)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Starting all the fixture processes")
err = fixtures.Start()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to start successfully")
apiServerConf := fixtures.APIServer.(*test.APIServer).Config
etcdConf := fixtures.Etcd.(*test.Etcd).Config
var apiServerURL, etcdClientURL, etcdPeerURL *url.URL
etcdClientURL, err = url.Parse(etcdConf.ClientURL)
Expect(err).NotTo(HaveOccurred())
etcdPeerURL, err = url.Parse(etcdConf.PeerURL)
Expect(err).NotTo(HaveOccurred())
apiServerURL, err = url.Parse(apiServerConf.APIServerURL)
Expect(err).NotTo(HaveOccurred())
isEtcdListeningForClients := isSomethingListeningOnPort(etcdClientURL.Host)
isEtcdListeningForPeers := isSomethingListeningOnPort(etcdPeerURL.Host)
isAPIServerListening := isSomethingListeningOnPort(apiServerURL.Host) isAPIServerListening := isSomethingListeningOnPort(apiServerURL.Host)
By("Ensuring Etcd is listening")
Expect(isEtcdListeningForClients()).To(BeTrue(),
fmt.Sprintf("Expected Etcd to listen for clients on %s,", etcdClientURL.Host))
Expect(isEtcdListeningForPeers()).To(BeTrue(),
fmt.Sprintf("Expected Etcd to listen for peers on %s,", etcdPeerURL.Host))
By("Ensuring APIServer is listening") By("Ensuring APIServer is listening")
Expect(isAPIServerListening()).To(BeTrue(), Expect(isAPIServerListening()).To(BeTrue(),
fmt.Sprintf("Expected APIServer to listen on %s", apiServerURL.Host)) fmt.Sprintf("Expected APIServer to listen on %s", apiServerURL.Host))
@ -33,13 +53,19 @@ var _ = Describe("The Testing Framework", func() {
err = fixtures.Stop() err = fixtures.Stop()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to stop successfully") Expect(err).NotTo(HaveOccurred(), "Expected fixtures to stop successfully")
By("Ensuring Etcd is not listening anymore")
Expect(isEtcdListeningForClients()).To(BeFalse(), "Expected Etcd not to listen for clients anymore")
Expect(isEtcdListeningForPeers()).To(BeFalse(), "Expected Etcd not to listen for peers anymore")
By("Ensuring APIServer is not listening anymore") By("Ensuring APIServer is not listening anymore")
Expect(isAPIServerListening()).To(BeFalse(), "Expected APIServer not to listen anymore") Expect(isAPIServerListening()).To(BeFalse(), "Expected APIServer not to listen anymore")
}) })
Measure("It should be fast to bring up and tear down the fixtures", func(b Benchmarker) { Measure("It should be fast to bring up and tear down the fixtures", func(b Benchmarker) {
b.Time("lifecycle", func() { b.Time("lifecycle", func() {
fixtures := test.NewFixtures(defaultPathToEtcd, defaultPathToApiserver) fixtures, err := test.NewFixtures(defaultPathToEtcd, defaultPathToApiserver)
Expect(err).NotTo(HaveOccurred())
fixtures.Start() fixtures.Start()
fixtures.Stop() fixtures.Stop()
}) })

View File

@ -8,12 +8,10 @@ import (
) )
type FakeFixtureProcess struct { type FakeFixtureProcess struct {
StartStub func(config map[string]string) error StartStub func() error
startMutex sync.RWMutex startMutex sync.RWMutex
startArgsForCall []struct { startArgsForCall []struct{}
config map[string]string startReturns struct {
}
startReturns struct {
result1 error result1 error
} }
startReturnsOnCall map[int]struct { startReturnsOnCall map[int]struct {
@ -26,16 +24,14 @@ type FakeFixtureProcess struct {
invocationsMutex sync.RWMutex invocationsMutex sync.RWMutex
} }
func (fake *FakeFixtureProcess) Start(config map[string]string) error { func (fake *FakeFixtureProcess) Start() error {
fake.startMutex.Lock() fake.startMutex.Lock()
ret, specificReturn := fake.startReturnsOnCall[len(fake.startArgsForCall)] ret, specificReturn := fake.startReturnsOnCall[len(fake.startArgsForCall)]
fake.startArgsForCall = append(fake.startArgsForCall, struct { fake.startArgsForCall = append(fake.startArgsForCall, struct{}{})
config map[string]string fake.recordInvocation("Start", []interface{}{})
}{config})
fake.recordInvocation("Start", []interface{}{config})
fake.startMutex.Unlock() fake.startMutex.Unlock()
if fake.StartStub != nil { if fake.StartStub != nil {
return fake.StartStub(config) return fake.StartStub()
} }
if specificReturn { if specificReturn {
return ret.result1 return ret.result1
@ -49,12 +45,6 @@ func (fake *FakeFixtureProcess) StartCallCount() int {
return len(fake.startArgsForCall) return len(fake.startArgsForCall)
} }
func (fake *FakeFixtureProcess) StartArgsForCall(i int) map[string]string {
fake.startMutex.RLock()
defer fake.startMutex.RUnlock()
return fake.startArgsForCall[i].config
}
func (fake *FakeFixtureProcess) StartReturns(result1 error) { func (fake *FakeFixtureProcess) StartReturns(result1 error) {
fake.StartStub = nil fake.StartStub = nil
fake.startReturns = struct { fake.startReturns = struct {

View File

@ -1,89 +0,0 @@
// Code generated by counterfeiter. DO NOT EDIT.
package testfakes
import (
"sync"
)
type FakeListenURLGetter struct {
Stub func() (url string, err error)
mutex sync.RWMutex
argsForCall []struct{}
returns struct {
result1 string
result2 error
}
returnsOnCall map[int]struct {
result1 string
result2 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *FakeListenURLGetter) Spy() (url string, err error) {
fake.mutex.Lock()
ret, specificReturn := fake.returnsOnCall[len(fake.argsForCall)]
fake.argsForCall = append(fake.argsForCall, struct{}{})
fake.recordInvocation("listenURLGetter", []interface{}{})
fake.mutex.Unlock()
if fake.Stub != nil {
return fake.Stub()
}
if specificReturn {
return ret.result1, ret.result2
}
return fake.returns.result1, fake.returns.result2
}
func (fake *FakeListenURLGetter) CallCount() int {
fake.mutex.RLock()
defer fake.mutex.RUnlock()
return len(fake.argsForCall)
}
func (fake *FakeListenURLGetter) Returns(result1 string, result2 error) {
fake.Stub = nil
fake.returns = struct {
result1 string
result2 error
}{result1, result2}
}
func (fake *FakeListenURLGetter) ReturnsOnCall(i int, result1 string, result2 error) {
fake.Stub = nil
if fake.returnsOnCall == nil {
fake.returnsOnCall = make(map[int]struct {
result1 string
result2 error
})
}
fake.returnsOnCall[i] = struct {
result1 string
result2 error
}{result1, result2}
}
func (fake *FakeListenURLGetter) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.mutex.RLock()
defer fake.mutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *FakeListenURLGetter) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}