Rename "Fixtures" to "ControlPlane"

Updated all comments and other related occurances.
This commit is contained in:
Hannes Hörl 2017-12-13 12:22:12 +00:00
parent fd43bb888a
commit 519293f43b
9 changed files with 120 additions and 120 deletions

View File

@ -16,7 +16,7 @@ type APIServer struct {
PathFinder BinPathFinder PathFinder BinPathFinder
ProcessStarter simpleSessionStarter ProcessStarter simpleSessionStarter
CertDirManager certDirManager CertDirManager certDirManager
Etcd FixtureProcess Etcd ControlPlaneProcess
session SimpleSession session SimpleSession
stdOut *gbytes.Buffer stdOut *gbytes.Buffer
stdErr *gbytes.Buffer stdErr *gbytes.Buffer
@ -29,7 +29,7 @@ type certDirManager interface {
//go:generate counterfeiter . certDirManager //go:generate counterfeiter . certDirManager
// NewAPIServer creates a new APIServer Fixture Process // NewAPIServer creates a new APIServer Control Plane Process
func NewAPIServer() (*APIServer, error) { func NewAPIServer() (*APIServer, error) {
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)

View File

@ -20,7 +20,7 @@ var _ = Describe("Apiserver", func() {
fakeSession *testfakes.FakeSimpleSession fakeSession *testfakes.FakeSimpleSession
fakeCertDirManager *testfakes.FakeCertDirManager fakeCertDirManager *testfakes.FakeCertDirManager
apiServer *APIServer apiServer *APIServer
fakeEtcdProcess *testfakes.FakeFixtureProcess fakeEtcdProcess *testfakes.FakeControlPlaneProcess
fakePathFinder *testfakes.FakeBinPathFinder fakePathFinder *testfakes.FakeBinPathFinder
fakeAddressManager *testfakes.FakeAddressManager fakeAddressManager *testfakes.FakeAddressManager
) )
@ -28,7 +28,7 @@ var _ = Describe("Apiserver", func() {
BeforeEach(func() { BeforeEach(func() {
fakeSession = &testfakes.FakeSimpleSession{} fakeSession = &testfakes.FakeSimpleSession{}
fakeCertDirManager = &testfakes.FakeCertDirManager{} fakeCertDirManager = &testfakes.FakeCertDirManager{}
fakeEtcdProcess = &testfakes.FakeFixtureProcess{} fakeEtcdProcess = &testfakes.FakeControlPlaneProcess{}
fakePathFinder = &testfakes.FakeBinPathFinder{} fakePathFinder = &testfakes.FakeBinPathFinder{}
fakeAddressManager = &testfakes.FakeAddressManager{} fakeAddressManager = &testfakes.FakeAddressManager{}

View File

@ -0,0 +1,66 @@
package test
// ControlPlane is a struct that knows how to start your test control plane.
//
// Right now, that means Etcd and your APIServer. This is likely to increase in future.
type ControlPlane struct {
APIServer ControlPlaneProcess
}
// ControlPlaneProcess knows how to start and stop a ControlPlane process.
// This interface is potentially going to be expanded to e.g. allow access to the processes StdOut/StdErr
// and other internals.
type ControlPlaneProcess interface {
Start() error
Stop() error
URL() (string, error)
}
//go:generate counterfeiter . ControlPlaneProcess
// NewControlPlane will give you a ControlPlane struct that's properly wired together.
func NewControlPlane() (*ControlPlane, error) {
apiServer, err := NewAPIServer()
if err != nil {
return nil, err
}
controlPlane := &ControlPlane{
APIServer: apiServer,
}
return controlPlane, nil
}
// Start will start your control plane. To stop it, call Stop().
func (f *ControlPlane) Start() error {
started := make(chan error)
starter := func(process ControlPlaneProcess) {
started <- process.Start()
}
processes := []ControlPlaneProcess{
f.APIServer,
}
for _, process := range processes {
go starter(process)
}
for range processes {
if err := <-started; err != nil {
return err
}
}
return nil
}
// Stop will stop your control plane, and clean up their data.
func (f *ControlPlane) Stop() error {
return f.APIServer.Stop()
}
// APIServerURL returns the URL to the APIServer. Clients can use this URL to connect to the APIServer.
func (f *ControlPlane) APIServerURL() (string, error) {
return f.APIServer.URL()
}

View File

@ -10,26 +10,26 @@ import (
"k8s.io/kubectl/pkg/framework/test/testfakes" "k8s.io/kubectl/pkg/framework/test/testfakes"
) )
var _ = Describe("Fixtures", func() { var _ = Describe("ControlPlane", func() {
It("can construct a properly wired Fixtures struct", func() { It("can construct a properly wired ControlPlane struct", func() {
_, err := NewFixtures() _, err := NewControlPlane()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
Context("with a properly configured set of Fixtures", func() { Context("with a properly configured set of ControlPlane", func() {
var ( var (
fakeAPIServerProcess *testfakes.FakeFixtureProcess fakeAPIServerProcess *testfakes.FakeControlPlaneProcess
fixtures Fixtures controlPlane ControlPlane
) )
BeforeEach(func() { BeforeEach(func() {
fakeAPIServerProcess = &testfakes.FakeFixtureProcess{} fakeAPIServerProcess = &testfakes.FakeControlPlaneProcess{}
fixtures = Fixtures{ controlPlane = ControlPlane{
APIServer: fakeAPIServerProcess, APIServer: fakeAPIServerProcess,
} }
}) })
It("can start them", func() { It("can start them", func() {
err := fixtures.Start() err := controlPlane.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("starting APIServer") By("starting APIServer")
@ -40,20 +40,20 @@ var _ = Describe("Fixtures", func() {
Context("when starting APIServer fails", func() { Context("when starting APIServer fails", func() {
It("propagates the error", func() { It("propagates the error", func() {
fakeAPIServerProcess.StartReturns(fmt.Errorf("another error")) fakeAPIServerProcess.StartReturns(fmt.Errorf("another error"))
err := fixtures.Start() err := controlPlane.Start()
Expect(err).To(MatchError(ContainSubstring("another error"))) Expect(err).To(MatchError(ContainSubstring("another error")))
}) })
}) })
It("can can clean up the temporary directory and stop", func() { It("can can clean up the temporary directory and stop", func() {
fixtures.Stop() controlPlane.Stop()
Expect(fakeAPIServerProcess.StopCallCount()).To(Equal(1)) Expect(fakeAPIServerProcess.StopCallCount()).To(Equal(1))
}) })
Context("when stopping APIServer fails", func() { Context("when stopping APIServer fails", func() {
It("propagates the error", func() { It("propagates the error", func() {
fakeAPIServerProcess.StopReturns(fmt.Errorf("error on stop")) fakeAPIServerProcess.StopReturns(fmt.Errorf("error on stop"))
err := fixtures.Stop() err := controlPlane.Stop()
Expect(err).To(MatchError(ContainSubstring("error on stop"))) Expect(err).To(MatchError(ContainSubstring("error on stop")))
}) })
}) })
@ -61,7 +61,7 @@ var _ = Describe("Fixtures", func() {
It("can be queried for the APIServer URL", func() { It("can be queried for the APIServer URL", func() {
fakeAPIServerProcess.URLReturns("some url to the apiserver", nil) fakeAPIServerProcess.URLReturns("some url to the apiserver", nil)
url, err := fixtures.APIServerURL() url, err := controlPlane.APIServerURL()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(url).To(Equal("some url to the apiserver")) Expect(url).To(Equal("some url to the apiserver"))
}) })
@ -69,7 +69,7 @@ var _ = Describe("Fixtures", func() {
Context("when querying the URL fails", func() { Context("when querying the URL fails", func() {
It("propagates the error", func() { It("propagates the error", func() {
fakeAPIServerProcess.URLReturns("", fmt.Errorf("URL error")) fakeAPIServerProcess.URLReturns("", fmt.Errorf("URL error"))
_, err := fixtures.APIServerURL() _, err := controlPlane.APIServerURL()
Expect(err).To(MatchError(ContainSubstring("URL error"))) Expect(err).To(MatchError(ContainSubstring("URL error")))
}) })
}) })

View File

@ -17,7 +17,7 @@ func TestIntegration(t *testing.T) {
var ( var (
pathToDemoCommand string pathToDemoCommand string
fixtures *test.Fixtures controlPlane *test.ControlPlane
) )
var _ = BeforeSuite(func() { var _ = BeforeSuite(func() {
@ -25,14 +25,14 @@ var _ = BeforeSuite(func() {
pathToDemoCommand, err = gexec.Build("k8s.io/kubectl/pkg/framework/test/democli/") pathToDemoCommand, err = gexec.Build("k8s.io/kubectl/pkg/framework/test/democli/")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
fixtures, err = test.NewFixtures() controlPlane, err = test.NewControlPlane()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = fixtures.Start() err = controlPlane.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
var _ = AfterSuite(func() { var _ = AfterSuite(func() {
fixtures.Stop() controlPlane.Stop()
gexec.CleanupBuildArtifacts() gexec.CleanupBuildArtifacts()
}) })

View File

@ -21,7 +21,7 @@ var _ = Describe("DemoCLI Integration", func() {
}) })
It("can get a list of pods", func() { It("can get a list of pods", func() {
apiURL, err := fixtures.APIServerURL() apiURL, err := controlPlane.APIServerURL()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
command := exec.Command(pathToDemoCommand, "listPods", "--api-url", apiURL) command := exec.Command(pathToDemoCommand, "listPods", "--api-url", apiURL)

View File

@ -1,66 +0,0 @@
package test
// Fixtures is a struct that knows how to start all your test fixtures.
//
// Right now, that means Etcd and your APIServer. This is likely to increase in future.
type Fixtures struct {
APIServer FixtureProcess
}
// FixtureProcess knows how to start and stop a Fixture processes.
// This interface is potentially going to be expanded to e.g. allow access to the processes StdOut/StdErr
// and other internals.
type FixtureProcess interface {
Start() error
Stop() error
URL() (string, error)
}
//go:generate counterfeiter . FixtureProcess
// NewFixtures will give you a Fixtures struct that's properly wired together.
func NewFixtures() (*Fixtures, error) {
apiServer, err := NewAPIServer()
if err != nil {
return nil, err
}
fixtures := &Fixtures{
APIServer: apiServer,
}
return fixtures, nil
}
// Start will start all your fixtures. To stop them, call Stop().
func (f *Fixtures) Start() error {
started := make(chan error)
starter := func(process FixtureProcess) {
started <- process.Start()
}
processes := []FixtureProcess{
f.APIServer,
}
for _, process := range processes {
go starter(process)
}
for range processes {
if err := <-started; err != nil {
return err
}
}
return nil
}
// Stop will stop all your fixtures, and clean up their data.
func (f *Fixtures) Stop() error {
return f.APIServer.Stop()
}
// APIServerURL returns the URL to the APIServer. Clients can use this URL to connect to the APIServer.
func (f *Fixtures) APIServerURL() (string, error) {
return f.APIServer.URL()
}

View File

@ -13,23 +13,23 @@ import (
) )
var _ = Describe("The Testing Framework", func() { var _ = Describe("The Testing Framework", func() {
It("Successfully manages the fixtures lifecycle", func() { It("Successfully manages the control plane lifecycle", func() {
var err error var err error
var fixtures *test.Fixtures var controlPlane *test.ControlPlane
fixtures, err = test.NewFixtures() controlPlane, err = test.NewControlPlane()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Starting all the fixture processes") By("Starting all the control plane processes")
err = fixtures.Start() err = controlPlane.Start()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to start successfully") Expect(err).NotTo(HaveOccurred(), "Expected controlPlane to start successfully")
var apiServerURL, etcdClientURL *url.URL var apiServerURL, etcdClientURL *url.URL
etcdUrlString, err := fixtures.APIServer.(*test.APIServer).Etcd.URL() etcdUrlString, err := controlPlane.APIServer.(*test.APIServer).Etcd.URL()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
etcdClientURL, err = url.Parse(etcdUrlString) etcdClientURL, err = url.Parse(etcdUrlString)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
urlString, err := fixtures.APIServerURL() urlString, err := controlPlane.APIServerURL()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
apiServerURL, err = url.Parse(urlString) apiServerURL, err = url.Parse(urlString)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -45,9 +45,9 @@ var _ = Describe("The Testing Framework", func() {
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))
By("Stopping all the fixture processes") By("Stopping all the control plane processes")
err = fixtures.Stop() err = controlPlane.Stop()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to stop successfully") Expect(err).NotTo(HaveOccurred(), "Expected controlPlane to stop successfully")
By("Ensuring Etcd is not listening anymore") By("Ensuring Etcd is not listening anymore")
Expect(isEtcdListeningForClients()).To(BeFalse(), "Expected Etcd not to listen for clients anymore") Expect(isEtcdListeningForClients()).To(BeFalse(), "Expected Etcd not to listen for clients anymore")
@ -56,13 +56,13 @@ var _ = Describe("The Testing Framework", func() {
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 control plane", func(b Benchmarker) {
b.Time("lifecycle", func() { b.Time("lifecycle", func() {
fixtures, err := test.NewFixtures() controlPlane, err := test.NewControlPlane()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
fixtures.Start() controlPlane.Start()
fixtures.Stop() controlPlane.Stop()
}) })
}, 10) }, 10)
}) })

View File

@ -7,7 +7,7 @@ import (
"k8s.io/kubectl/pkg/framework/test" "k8s.io/kubectl/pkg/framework/test"
) )
type FakeFixtureProcess struct { type FakeControlPlaneProcess struct {
StartStub func() error StartStub func() error
startMutex sync.RWMutex startMutex sync.RWMutex
startArgsForCall []struct{} startArgsForCall []struct{}
@ -41,7 +41,7 @@ type FakeFixtureProcess struct {
invocationsMutex sync.RWMutex invocationsMutex sync.RWMutex
} }
func (fake *FakeFixtureProcess) Start() error { func (fake *FakeControlPlaneProcess) 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{}{})
@ -56,20 +56,20 @@ func (fake *FakeFixtureProcess) Start() error {
return fake.startReturns.result1 return fake.startReturns.result1
} }
func (fake *FakeFixtureProcess) StartCallCount() int { func (fake *FakeControlPlaneProcess) StartCallCount() int {
fake.startMutex.RLock() fake.startMutex.RLock()
defer fake.startMutex.RUnlock() defer fake.startMutex.RUnlock()
return len(fake.startArgsForCall) return len(fake.startArgsForCall)
} }
func (fake *FakeFixtureProcess) StartReturns(result1 error) { func (fake *FakeControlPlaneProcess) StartReturns(result1 error) {
fake.StartStub = nil fake.StartStub = nil
fake.startReturns = struct { fake.startReturns = struct {
result1 error result1 error
}{result1} }{result1}
} }
func (fake *FakeFixtureProcess) StartReturnsOnCall(i int, result1 error) { func (fake *FakeControlPlaneProcess) StartReturnsOnCall(i int, result1 error) {
fake.StartStub = nil fake.StartStub = nil
if fake.startReturnsOnCall == nil { if fake.startReturnsOnCall == nil {
fake.startReturnsOnCall = make(map[int]struct { fake.startReturnsOnCall = make(map[int]struct {
@ -81,7 +81,7 @@ func (fake *FakeFixtureProcess) StartReturnsOnCall(i int, result1 error) {
}{result1} }{result1}
} }
func (fake *FakeFixtureProcess) Stop() error { func (fake *FakeControlPlaneProcess) Stop() error {
fake.stopMutex.Lock() fake.stopMutex.Lock()
ret, specificReturn := fake.stopReturnsOnCall[len(fake.stopArgsForCall)] ret, specificReturn := fake.stopReturnsOnCall[len(fake.stopArgsForCall)]
fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{}) fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{})
@ -96,20 +96,20 @@ func (fake *FakeFixtureProcess) Stop() error {
return fake.stopReturns.result1 return fake.stopReturns.result1
} }
func (fake *FakeFixtureProcess) StopCallCount() int { func (fake *FakeControlPlaneProcess) StopCallCount() int {
fake.stopMutex.RLock() fake.stopMutex.RLock()
defer fake.stopMutex.RUnlock() defer fake.stopMutex.RUnlock()
return len(fake.stopArgsForCall) return len(fake.stopArgsForCall)
} }
func (fake *FakeFixtureProcess) StopReturns(result1 error) { func (fake *FakeControlPlaneProcess) StopReturns(result1 error) {
fake.StopStub = nil fake.StopStub = nil
fake.stopReturns = struct { fake.stopReturns = struct {
result1 error result1 error
}{result1} }{result1}
} }
func (fake *FakeFixtureProcess) StopReturnsOnCall(i int, result1 error) { func (fake *FakeControlPlaneProcess) StopReturnsOnCall(i int, result1 error) {
fake.StopStub = nil fake.StopStub = nil
if fake.stopReturnsOnCall == nil { if fake.stopReturnsOnCall == nil {
fake.stopReturnsOnCall = make(map[int]struct { fake.stopReturnsOnCall = make(map[int]struct {
@ -121,7 +121,7 @@ func (fake *FakeFixtureProcess) StopReturnsOnCall(i int, result1 error) {
}{result1} }{result1}
} }
func (fake *FakeFixtureProcess) URL() (string, error) { func (fake *FakeControlPlaneProcess) URL() (string, error) {
fake.uRLMutex.Lock() fake.uRLMutex.Lock()
ret, specificReturn := fake.uRLReturnsOnCall[len(fake.uRLArgsForCall)] ret, specificReturn := fake.uRLReturnsOnCall[len(fake.uRLArgsForCall)]
fake.uRLArgsForCall = append(fake.uRLArgsForCall, struct{}{}) fake.uRLArgsForCall = append(fake.uRLArgsForCall, struct{}{})
@ -136,13 +136,13 @@ func (fake *FakeFixtureProcess) URL() (string, error) {
return fake.uRLReturns.result1, fake.uRLReturns.result2 return fake.uRLReturns.result1, fake.uRLReturns.result2
} }
func (fake *FakeFixtureProcess) URLCallCount() int { func (fake *FakeControlPlaneProcess) URLCallCount() int {
fake.uRLMutex.RLock() fake.uRLMutex.RLock()
defer fake.uRLMutex.RUnlock() defer fake.uRLMutex.RUnlock()
return len(fake.uRLArgsForCall) return len(fake.uRLArgsForCall)
} }
func (fake *FakeFixtureProcess) URLReturns(result1 string, result2 error) { func (fake *FakeControlPlaneProcess) URLReturns(result1 string, result2 error) {
fake.URLStub = nil fake.URLStub = nil
fake.uRLReturns = struct { fake.uRLReturns = struct {
result1 string result1 string
@ -150,7 +150,7 @@ func (fake *FakeFixtureProcess) URLReturns(result1 string, result2 error) {
}{result1, result2} }{result1, result2}
} }
func (fake *FakeFixtureProcess) URLReturnsOnCall(i int, result1 string, result2 error) { func (fake *FakeControlPlaneProcess) URLReturnsOnCall(i int, result1 string, result2 error) {
fake.URLStub = nil fake.URLStub = nil
if fake.uRLReturnsOnCall == nil { if fake.uRLReturnsOnCall == nil {
fake.uRLReturnsOnCall = make(map[int]struct { fake.uRLReturnsOnCall = make(map[int]struct {
@ -164,7 +164,7 @@ func (fake *FakeFixtureProcess) URLReturnsOnCall(i int, result1 string, result2
}{result1, result2} }{result1, result2}
} }
func (fake *FakeFixtureProcess) Invocations() map[string][][]interface{} { func (fake *FakeControlPlaneProcess) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock() fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock() defer fake.invocationsMutex.RUnlock()
fake.startMutex.RLock() fake.startMutex.RLock()
@ -180,7 +180,7 @@ func (fake *FakeFixtureProcess) Invocations() map[string][][]interface{} {
return copiedInvocations return copiedInvocations
} }
func (fake *FakeFixtureProcess) recordInvocation(key string, args []interface{}) { func (fake *FakeControlPlaneProcess) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock() fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock() defer fake.invocationsMutex.Unlock()
if fake.invocations == nil { if fake.invocations == nil {
@ -192,4 +192,4 @@ func (fake *FakeFixtureProcess) recordInvocation(key string, args []interface{})
fake.invocations[key] = append(fake.invocations[key], args) fake.invocations[key] = append(fake.invocations[key], args)
} }
var _ test.FixtureProcess = new(FakeFixtureProcess) var _ test.ControlPlaneProcess = new(FakeControlPlaneProcess)