diff --git a/pkg/framework/test/apiserver.go b/pkg/framework/test/apiserver.go index 46e165d61..92dfa0f89 100644 --- a/pkg/framework/test/apiserver.go +++ b/pkg/framework/test/apiserver.go @@ -31,8 +31,24 @@ type certDirManager interface { //go:generate counterfeiter . certDirManager -// NewAPIServer creates a new APIServer Fixture Process -func NewAPIServer(pathToAPIServer string, config *APIServerConfig) *APIServer { +var apiServerBinPathFinder = DefaultBinPathFinder + +// NewAPIServer constructs a new APIServer with whatever api_server binary it can find. +func NewAPIServer(config *APIServerConfig) *APIServer { + starter := func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) { + return gexec.Start(command, out, err) + } + + return &APIServer{ + Path: apiServerBinPathFinder("kube_apiserver"), + Config: config, + ProcessStarter: starter, + CertDirManager: &TempDirManager{}, + } +} + +// NewAPIServerWithBinary creates a new APIServer Fixture Process +func NewAPIServerWithBinary(pathToAPIServer string, config *APIServerConfig) *APIServer { starter := func(command *exec.Cmd, out, err io.Writer) (SimpleSession, error) { return gexec.Start(command, out, err) } diff --git a/pkg/framework/test/apiserver_constructor_test.go b/pkg/framework/test/apiserver_constructor_test.go new file mode 100644 index 000000000..7fc9850d2 --- /dev/null +++ b/pkg/framework/test/apiserver_constructor_test.go @@ -0,0 +1,35 @@ +package test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("NewAPIServer", func() { + var oldAPIServerBinPathFinder BinPathFinder + BeforeEach(func() { + oldAPIServerBinPathFinder = apiServerBinPathFinder + }) + AfterEach(func() { + apiServerBinPathFinder = oldAPIServerBinPathFinder + }) + + It("can construct a properly configured APIServer", func() { + config := &APIServerConfig{ + EtcdURL: "some etcd URL", + APIServerURL: "some APIServer URL", + } + apiServerBinPathFinder = func(name string) string { + Expect(name).To(Equal("kube_apiserver")) + return "some api server path" + } + + apiServer := NewAPIServer(config) + + Expect(apiServer).NotTo(BeNil()) + Expect(apiServer.ProcessStarter).NotTo(BeNil()) + Expect(apiServer.CertDirManager).NotTo(BeNil()) + Expect(apiServer.Path).To(Equal("some api server path")) + Expect(apiServer.Config).To(Equal(config)) + }) +}) diff --git a/pkg/framework/test/fixtures.go b/pkg/framework/test/fixtures.go index b8e40c988..d3dca841b 100644 --- a/pkg/framework/test/fixtures.go +++ b/pkg/framework/test/fixtures.go @@ -48,7 +48,7 @@ func NewFixtures(pathToEtcd, pathToAPIServer string) (*Fixtures, error) { fixtures := &Fixtures{ Etcd: NewEtcdWithBinaryAndConfig(pathToEtcd, etcdConfig), - APIServer: NewAPIServer(pathToAPIServer, apiServerConfig), + APIServer: NewAPIServerWithBinary(pathToAPIServer, apiServerConfig), } fixtures.Config = FixturesConfig{