diff --git a/pkg/framework/test/fixtures.go b/pkg/framework/test/fixtures.go index 6fe3dd96..cb7376f4 100644 --- a/pkg/framework/test/fixtures.go +++ b/pkg/framework/test/fixtures.go @@ -8,8 +8,8 @@ import ( // // Right now, that means Etcd and your APIServer. This is likely to increase in future. type Fixtures struct { - Etcd EtcdStartStopper - APIServer APIServerStartStopper + Etcd FixtureProcess + APIServer FixtureProcess } // EtcdStartStopper knows how to start an Etcd. One good implementation is Etcd. @@ -28,6 +28,16 @@ type APIServerStartStopper interface { //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. func NewFixtures(pathToEtcd, pathToAPIServer string) *Fixtures { etcdURL := "http://127.0.0.1:2379" diff --git a/pkg/framework/test/fixtures_test.go b/pkg/framework/test/fixtures_test.go index 19ae1d73..ee542dcb 100644 --- a/pkg/framework/test/fixtures_test.go +++ b/pkg/framework/test/fixtures_test.go @@ -19,16 +19,16 @@ var _ = Describe("Fixtures", func() { Context("with a properly configured set of Fixtures", func() { var ( - fakeEtcdStartStopper *testfakes.FakeEtcdStartStopper - fakeAPIServerStartStopper *testfakes.FakeAPIServerStartStopper - fixtures Fixtures + fakeEtcdProcess *testfakes.FakeFixtureProcess + fakeAPIServerProcess *testfakes.FakeFixtureProcess + fixtures Fixtures ) BeforeEach(func() { - fakeEtcdStartStopper = &testfakes.FakeEtcdStartStopper{} - fakeAPIServerStartStopper = &testfakes.FakeAPIServerStartStopper{} + fakeEtcdProcess = &testfakes.FakeFixtureProcess{} + fakeAPIServerProcess = &testfakes.FakeFixtureProcess{} fixtures = Fixtures{ - Etcd: fakeEtcdStartStopper, - APIServer: fakeAPIServerStartStopper, + Etcd: fakeEtcdProcess, + APIServer: fakeAPIServerProcess, } }) @@ -37,17 +37,17 @@ var _ = Describe("Fixtures", func() { Expect(err).NotTo(HaveOccurred()) By("starting Etcd") - Expect(fakeEtcdStartStopper.StartCallCount()).To(Equal(1), + Expect(fakeEtcdProcess.StartCallCount()).To(Equal(1), "the EtcdStartStopper should be called exactly once") By("starting APIServer") - Expect(fakeAPIServerStartStopper.StartCallCount()).To(Equal(1), + Expect(fakeAPIServerProcess.StartCallCount()).To(Equal(1), "the APIServerStartStopper should be called exactly once") }) Context("when starting etcd fails", func() { It("wraps the error", func() { - fakeEtcdStartStopper.StartReturns(fmt.Errorf("some error")) + fakeEtcdProcess.StartReturns(fmt.Errorf("some error")) err := fixtures.Start() Expect(err).To(MatchError(ContainSubstring("some error"))) }) @@ -55,7 +55,7 @@ var _ = Describe("Fixtures", func() { Context("when starting APIServer fails", func() { It("wraps the error", func() { - fakeAPIServerStartStopper.StartReturns(fmt.Errorf("another error")) + fakeAPIServerProcess.StartReturns(fmt.Errorf("another error")) err := fixtures.Start() 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() { fixtures.Stop() - Expect(fakeEtcdStartStopper.StopCallCount()).To(Equal(1)) - Expect(fakeAPIServerStartStopper.StopCallCount()).To(Equal(1)) + Expect(fakeEtcdProcess.StopCallCount()).To(Equal(1)) + Expect(fakeAPIServerProcess.StopCallCount()).To(Equal(1)) }) }) diff --git a/pkg/framework/test/testfakes/fake_apiserver_start_stopper.go b/pkg/framework/test/testfakes/fake_apiserver_start_stopper.go deleted file mode 100644 index beced41a..00000000 --- a/pkg/framework/test/testfakes/fake_apiserver_start_stopper.go +++ /dev/null @@ -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) diff --git a/pkg/framework/test/testfakes/fake_etcd_start_stopper.go b/pkg/framework/test/testfakes/fake_fixture_process.go similarity index 78% rename from pkg/framework/test/testfakes/fake_etcd_start_stopper.go rename to pkg/framework/test/testfakes/fake_fixture_process.go index d8477a03..9b0c0cb2 100644 --- a/pkg/framework/test/testfakes/fake_etcd_start_stopper.go +++ b/pkg/framework/test/testfakes/fake_fixture_process.go @@ -7,7 +7,7 @@ import ( "k8s.io/kubectl/pkg/framework/test" ) -type FakeEtcdStartStopper struct { +type FakeFixtureProcess struct { StartStub func() error startMutex sync.RWMutex startArgsForCall []struct{} @@ -24,7 +24,7 @@ type FakeEtcdStartStopper struct { invocationsMutex sync.RWMutex } -func (fake *FakeEtcdStartStopper) Start() error { +func (fake *FakeFixtureProcess) Start() error { fake.startMutex.Lock() ret, specificReturn := fake.startReturnsOnCall[len(fake.startArgsForCall)] fake.startArgsForCall = append(fake.startArgsForCall, struct{}{}) @@ -39,20 +39,20 @@ func (fake *FakeEtcdStartStopper) Start() error { return fake.startReturns.result1 } -func (fake *FakeEtcdStartStopper) StartCallCount() int { +func (fake *FakeFixtureProcess) StartCallCount() int { fake.startMutex.RLock() defer fake.startMutex.RUnlock() return len(fake.startArgsForCall) } -func (fake *FakeEtcdStartStopper) StartReturns(result1 error) { +func (fake *FakeFixtureProcess) StartReturns(result1 error) { fake.StartStub = nil fake.startReturns = struct { result1 error }{result1} } -func (fake *FakeEtcdStartStopper) StartReturnsOnCall(i int, result1 error) { +func (fake *FakeFixtureProcess) StartReturnsOnCall(i int, result1 error) { fake.StartStub = nil if fake.startReturnsOnCall == nil { fake.startReturnsOnCall = make(map[int]struct { @@ -64,7 +64,7 @@ func (fake *FakeEtcdStartStopper) StartReturnsOnCall(i int, result1 error) { }{result1} } -func (fake *FakeEtcdStartStopper) Stop() { +func (fake *FakeFixtureProcess) Stop() { fake.stopMutex.Lock() fake.stopArgsForCall = append(fake.stopArgsForCall, struct{}{}) 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() defer fake.stopMutex.RUnlock() return len(fake.stopArgsForCall) } -func (fake *FakeEtcdStartStopper) Invocations() map[string][][]interface{} { +func (fake *FakeFixtureProcess) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() fake.startMutex.RLock() @@ -94,7 +94,7 @@ func (fake *FakeEtcdStartStopper) Invocations() map[string][][]interface{} { return copiedInvocations } -func (fake *FakeEtcdStartStopper) recordInvocation(key string, args []interface{}) { +func (fake *FakeFixtureProcess) recordInvocation(key string, args []interface{}) { fake.invocationsMutex.Lock() defer fake.invocationsMutex.Unlock() if fake.invocations == nil { @@ -106,4 +106,4 @@ func (fake *FakeEtcdStartStopper) recordInvocation(key string, args []interface{ fake.invocations[key] = append(fake.invocations[key], args) } -var _ test.EtcdStartStopper = new(FakeEtcdStartStopper) +var _ test.FixtureProcess = new(FakeFixtureProcess)