Unify fixture processes
Instead of the separate {Etcd,APIServer}StartStopper use the unified interface FixtureProcess
This commit is contained in:
parent
940bec8b1c
commit
ddd0a5683f
|
@ -8,8 +8,8 @@ import (
|
||||||
//
|
//
|
||||||
// Right now, that means Etcd and your APIServer. This is likely to increase in future.
|
// Right now, that means Etcd and your APIServer. This is likely to increase in future.
|
||||||
type Fixtures struct {
|
type Fixtures struct {
|
||||||
Etcd EtcdStartStopper
|
Etcd FixtureProcess
|
||||||
APIServer APIServerStartStopper
|
APIServer FixtureProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
// EtcdStartStopper knows how to start an Etcd. One good implementation is Etcd.
|
// EtcdStartStopper knows how to start an Etcd. One good implementation is Etcd.
|
||||||
|
@ -28,6 +28,16 @@ type APIServerStartStopper interface {
|
||||||
|
|
||||||
//go:generate counterfeiter . APIServerStartStopper
|
//go:generate counterfeiter . APIServerStartStopper
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
//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 {
|
||||||
etcdURL := "http://127.0.0.1:2379"
|
etcdURL := "http://127.0.0.1:2379"
|
||||||
|
|
|
@ -19,16 +19,16 @@ var _ = Describe("Fixtures", func() {
|
||||||
|
|
||||||
Context("with a properly configured set of Fixtures", func() {
|
Context("with a properly configured set of Fixtures", func() {
|
||||||
var (
|
var (
|
||||||
fakeEtcdStartStopper *testfakes.FakeEtcdStartStopper
|
fakeEtcdProcess *testfakes.FakeFixtureProcess
|
||||||
fakeAPIServerStartStopper *testfakes.FakeAPIServerStartStopper
|
fakeAPIServerProcess *testfakes.FakeFixtureProcess
|
||||||
fixtures Fixtures
|
fixtures Fixtures
|
||||||
)
|
)
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
fakeEtcdStartStopper = &testfakes.FakeEtcdStartStopper{}
|
fakeEtcdProcess = &testfakes.FakeFixtureProcess{}
|
||||||
fakeAPIServerStartStopper = &testfakes.FakeAPIServerStartStopper{}
|
fakeAPIServerProcess = &testfakes.FakeFixtureProcess{}
|
||||||
fixtures = Fixtures{
|
fixtures = Fixtures{
|
||||||
Etcd: fakeEtcdStartStopper,
|
Etcd: fakeEtcdProcess,
|
||||||
APIServer: fakeAPIServerStartStopper,
|
APIServer: fakeAPIServerProcess,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -37,17 +37,17 @@ var _ = Describe("Fixtures", func() {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("starting Etcd")
|
By("starting Etcd")
|
||||||
Expect(fakeEtcdStartStopper.StartCallCount()).To(Equal(1),
|
Expect(fakeEtcdProcess.StartCallCount()).To(Equal(1),
|
||||||
"the EtcdStartStopper should be called exactly once")
|
"the EtcdStartStopper should be called exactly once")
|
||||||
|
|
||||||
By("starting APIServer")
|
By("starting APIServer")
|
||||||
Expect(fakeAPIServerStartStopper.StartCallCount()).To(Equal(1),
|
Expect(fakeAPIServerProcess.StartCallCount()).To(Equal(1),
|
||||||
"the APIServerStartStopper should be called exactly once")
|
"the APIServerStartStopper should be called exactly once")
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("when starting etcd fails", func() {
|
Context("when starting etcd fails", func() {
|
||||||
It("wraps the error", func() {
|
It("wraps the error", func() {
|
||||||
fakeEtcdStartStopper.StartReturns(fmt.Errorf("some error"))
|
fakeEtcdProcess.StartReturns(fmt.Errorf("some error"))
|
||||||
err := fixtures.Start()
|
err := fixtures.Start()
|
||||||
Expect(err).To(MatchError(ContainSubstring("some error")))
|
Expect(err).To(MatchError(ContainSubstring("some error")))
|
||||||
})
|
})
|
||||||
|
@ -55,7 +55,7 @@ var _ = Describe("Fixtures", func() {
|
||||||
|
|
||||||
Context("when starting APIServer fails", func() {
|
Context("when starting APIServer fails", func() {
|
||||||
It("wraps the error", func() {
|
It("wraps the error", func() {
|
||||||
fakeAPIServerStartStopper.StartReturns(fmt.Errorf("another error"))
|
fakeAPIServerProcess.StartReturns(fmt.Errorf("another error"))
|
||||||
err := fixtures.Start()
|
err := fixtures.Start()
|
||||||
Expect(err).To(MatchError(ContainSubstring("another error")))
|
Expect(err).To(MatchError(ContainSubstring("another error")))
|
||||||
})
|
})
|
||||||
|
@ -63,8 +63,8 @@ var _ = Describe("Fixtures", func() {
|
||||||
|
|
||||||
It("can can clean up the temporary directory and stop", func() {
|
It("can can clean up the temporary directory and stop", func() {
|
||||||
fixtures.Stop()
|
fixtures.Stop()
|
||||||
Expect(fakeEtcdStartStopper.StopCallCount()).To(Equal(1))
|
Expect(fakeEtcdProcess.StopCallCount()).To(Equal(1))
|
||||||
Expect(fakeAPIServerStartStopper.StopCallCount()).To(Equal(1))
|
Expect(fakeAPIServerProcess.StopCallCount()).To(Equal(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by counterfeiter. DO NOT EDIT.
|
|
||||||
package testfakes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"k8s.io/kubectl/pkg/framework/test"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FakeAPIServerStartStopper struct {
|
|
||||||
StartStub func() error
|
|
||||||
startMutex sync.RWMutex
|
|
||||||
startArgsForCall []struct{}
|
|
||||||
startReturns struct {
|
|
||||||
result1 error
|
|
||||||
}
|
|
||||||
startReturnsOnCall map[int]struct {
|
|
||||||
result1 error
|
|
||||||
}
|
|
||||||
StopStub func()
|
|
||||||
stopMutex sync.RWMutex
|
|
||||||
stopArgsForCall []struct{}
|
|
||||||
invocations map[string][][]interface{}
|
|
||||||
invocationsMutex sync.RWMutex
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) Start() error {
|
|
||||||
fake.startMutex.Lock()
|
|
||||||
ret, specificReturn := fake.startReturnsOnCall[len(fake.startArgsForCall)]
|
|
||||||
fake.startArgsForCall = append(fake.startArgsForCall, struct{}{})
|
|
||||||
fake.recordInvocation("Start", []interface{}{})
|
|
||||||
fake.startMutex.Unlock()
|
|
||||||
if fake.StartStub != nil {
|
|
||||||
return fake.StartStub()
|
|
||||||
}
|
|
||||||
if specificReturn {
|
|
||||||
return ret.result1
|
|
||||||
}
|
|
||||||
return fake.startReturns.result1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) StartCallCount() int {
|
|
||||||
fake.startMutex.RLock()
|
|
||||||
defer fake.startMutex.RUnlock()
|
|
||||||
return len(fake.startArgsForCall)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) StartReturns(result1 error) {
|
|
||||||
fake.StartStub = nil
|
|
||||||
fake.startReturns = struct {
|
|
||||||
result1 error
|
|
||||||
}{result1}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) StartReturnsOnCall(i int, result1 error) {
|
|
||||||
fake.StartStub = nil
|
|
||||||
if fake.startReturnsOnCall == nil {
|
|
||||||
fake.startReturnsOnCall = make(map[int]struct {
|
|
||||||
result1 error
|
|
||||||
})
|
|
||||||
}
|
|
||||||
fake.startReturnsOnCall[i] = struct {
|
|
||||||
result1 error
|
|
||||||
}{result1}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) Stop() {
|
|
||||||
fake.stopMutex.Lock()
|
|
||||||
fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{})
|
|
||||||
fake.recordInvocation("Stop", []interface{}{})
|
|
||||||
fake.stopMutex.Unlock()
|
|
||||||
if fake.StopStub != nil {
|
|
||||||
fake.StopStub()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) StopCallCount() int {
|
|
||||||
fake.stopMutex.RLock()
|
|
||||||
defer fake.stopMutex.RUnlock()
|
|
||||||
return len(fake.stopArgsForCall)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) Invocations() map[string][][]interface{} {
|
|
||||||
fake.invocationsMutex.RLock()
|
|
||||||
defer fake.invocationsMutex.RUnlock()
|
|
||||||
fake.startMutex.RLock()
|
|
||||||
defer fake.startMutex.RUnlock()
|
|
||||||
fake.stopMutex.RLock()
|
|
||||||
defer fake.stopMutex.RUnlock()
|
|
||||||
copiedInvocations := map[string][][]interface{}{}
|
|
||||||
for key, value := range fake.invocations {
|
|
||||||
copiedInvocations[key] = value
|
|
||||||
}
|
|
||||||
return copiedInvocations
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeAPIServerStartStopper) 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ test.APIServerStartStopper = new(FakeAPIServerStartStopper)
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"k8s.io/kubectl/pkg/framework/test"
|
"k8s.io/kubectl/pkg/framework/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeEtcdStartStopper struct {
|
type FakeFixtureProcess struct {
|
||||||
StartStub func() error
|
StartStub func() error
|
||||||
startMutex sync.RWMutex
|
startMutex sync.RWMutex
|
||||||
startArgsForCall []struct{}
|
startArgsForCall []struct{}
|
||||||
|
@ -24,7 +24,7 @@ type FakeEtcdStartStopper struct {
|
||||||
invocationsMutex sync.RWMutex
|
invocationsMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeEtcdStartStopper) Start() 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{}{})
|
||||||
|
@ -39,20 +39,20 @@ func (fake *FakeEtcdStartStopper) Start() error {
|
||||||
return fake.startReturns.result1
|
return fake.startReturns.result1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeEtcdStartStopper) StartCallCount() int {
|
func (fake *FakeFixtureProcess) 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 *FakeEtcdStartStopper) StartReturns(result1 error) {
|
func (fake *FakeFixtureProcess) StartReturns(result1 error) {
|
||||||
fake.StartStub = nil
|
fake.StartStub = nil
|
||||||
fake.startReturns = struct {
|
fake.startReturns = struct {
|
||||||
result1 error
|
result1 error
|
||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeEtcdStartStopper) StartReturnsOnCall(i int, result1 error) {
|
func (fake *FakeFixtureProcess) 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 {
|
||||||
|
@ -64,7 +64,7 @@ func (fake *FakeEtcdStartStopper) StartReturnsOnCall(i int, result1 error) {
|
||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeEtcdStartStopper) Stop() {
|
func (fake *FakeFixtureProcess) Stop() {
|
||||||
fake.stopMutex.Lock()
|
fake.stopMutex.Lock()
|
||||||
fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{})
|
fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{})
|
||||||
fake.recordInvocation("Stop", []interface{}{})
|
fake.recordInvocation("Stop", []interface{}{})
|
||||||
|
@ -74,13 +74,13 @@ func (fake *FakeEtcdStartStopper) Stop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeEtcdStartStopper) StopCallCount() int {
|
func (fake *FakeFixtureProcess) 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 *FakeEtcdStartStopper) Invocations() map[string][][]interface{} {
|
func (fake *FakeFixtureProcess) Invocations() map[string][][]interface{} {
|
||||||
fake.invocationsMutex.RLock()
|
fake.invocationsMutex.RLock()
|
||||||
defer fake.invocationsMutex.RUnlock()
|
defer fake.invocationsMutex.RUnlock()
|
||||||
fake.startMutex.RLock()
|
fake.startMutex.RLock()
|
||||||
|
@ -94,7 +94,7 @@ func (fake *FakeEtcdStartStopper) Invocations() map[string][][]interface{} {
|
||||||
return copiedInvocations
|
return copiedInvocations
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeEtcdStartStopper) recordInvocation(key string, args []interface{}) {
|
func (fake *FakeFixtureProcess) 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 {
|
||||||
|
@ -106,4 +106,4 @@ func (fake *FakeEtcdStartStopper) recordInvocation(key string, args []interface{
|
||||||
fake.invocations[key] = append(fake.invocations[key], args)
|
fake.invocations[key] = append(fake.invocations[key], args)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ test.EtcdStartStopper = new(FakeEtcdStartStopper)
|
var _ test.FixtureProcess = new(FakeFixtureProcess)
|
Loading…
Reference in New Issue