Add APIServer constructor with default binary path

This commit is contained in:
Hannes Hörl 2017-12-08 15:17:25 +00:00 committed by Gareth Smith
parent 3bdc1f4b9b
commit e6b042840b
3 changed files with 54 additions and 3 deletions

View File

@ -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)
}

View File

@ -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))
})
})

View File

@ -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{