Make Fixtures use pathless apiserver constructor
This is motivated by #162, but also involves changing the NewFixtures(...) constructor which is the entry point to the whole framework. We're removing the amount of config you need to make it work, in line with #163.
This commit is contained in:
parent
e6b042840b
commit
ad04fd8972
|
|
@ -33,34 +33,18 @@ type certDirManager interface {
|
||||||
|
|
||||||
var apiServerBinPathFinder = DefaultBinPathFinder
|
var apiServerBinPathFinder = DefaultBinPathFinder
|
||||||
|
|
||||||
// NewAPIServer constructs a new APIServer with whatever api_server binary it can find.
|
// NewAPIServer creates a new APIServer Fixture Process
|
||||||
func NewAPIServer(config *APIServerConfig) *APIServer {
|
func NewAPIServer(config *APIServerConfig) *APIServer {
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &APIServer{
|
return &APIServer{
|
||||||
Path: apiServerBinPathFinder("kube_apiserver"),
|
Path: apiServerBinPathFinder("kube-apiserver"),
|
||||||
Config: config,
|
Config: config,
|
||||||
ProcessStarter: starter,
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
apiserver := &APIServer{
|
|
||||||
Path: pathToAPIServer,
|
|
||||||
ProcessStarter: starter,
|
|
||||||
CertDirManager: NewTempDirManager(),
|
CertDirManager: NewTempDirManager(),
|
||||||
Config: config,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiserver
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the apiserver, waits for it to come up, and returns an error, if occoured.
|
// Start starts the apiserver, waits for it to come up, and returns an error, if occoured.
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ var _ = Describe("NewAPIServer", func() {
|
||||||
APIServerURL: "some APIServer URL",
|
APIServerURL: "some APIServer URL",
|
||||||
}
|
}
|
||||||
apiServerBinPathFinder = func(name string) string {
|
apiServerBinPathFinder = func(name string) string {
|
||||||
Expect(name).To(Equal("kube_apiserver"))
|
Expect(name).To(Equal("kube-apiserver"))
|
||||||
return "some api server path"
|
return "some api server path"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,19 +32,14 @@ var _ = BeforeSuite(func() {
|
||||||
Expect(ok).NotTo(BeFalse())
|
Expect(ok).NotTo(BeFalse())
|
||||||
defaultAssetsDir := filepath.Clean(filepath.Join(filepath.Dir(thisFile), "..", "..", "assets", "bin"))
|
defaultAssetsDir := filepath.Clean(filepath.Join(filepath.Dir(thisFile), "..", "..", "assets", "bin"))
|
||||||
pathToEtcd := filepath.Join(defaultAssetsDir, "etcd")
|
pathToEtcd := filepath.Join(defaultAssetsDir, "etcd")
|
||||||
pathToAPIServer := filepath.Join(defaultAssetsDir, "kube-apiserver")
|
|
||||||
|
|
||||||
if pathToBin, ok := os.LookupEnv("TEST_ETCD_BIN"); ok {
|
if pathToBin, ok := os.LookupEnv("TEST_ETCD_BIN"); ok {
|
||||||
pathToEtcd = pathToBin
|
pathToEtcd = pathToBin
|
||||||
}
|
}
|
||||||
if pathToBin, ok := os.LookupEnv("TEST_APISERVER_BIN"); ok {
|
|
||||||
pathToAPIServer = pathToBin
|
|
||||||
}
|
|
||||||
|
|
||||||
Expect(pathToEtcd).NotTo(BeEmpty(), "Path to etcd cannot be empty, set $TEST_ETCD_BIN")
|
Expect(pathToEtcd).NotTo(BeEmpty(), "Path to etcd cannot be empty, set $TEST_ETCD_BIN")
|
||||||
Expect(pathToAPIServer).NotTo(BeEmpty(), "Path to apiserver cannot be empty, set $TEST_APISERVER_BIN")
|
|
||||||
|
|
||||||
fixtures, err = test.NewFixtures(pathToEtcd, pathToAPIServer)
|
fixtures, err = test.NewFixtures(pathToEtcd)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = fixtures.Start()
|
err = fixtures.Start()
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type FixtureProcess interface {
|
||||||
//go:generate counterfeiter . FixtureProcess
|
//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, error) {
|
func NewFixtures(pathToEtcd string) (*Fixtures, error) {
|
||||||
etcdConfig, err := NewEtcdConfig()
|
etcdConfig, err := NewEtcdConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -48,7 +48,7 @@ func NewFixtures(pathToEtcd, pathToAPIServer string) (*Fixtures, error) {
|
||||||
|
|
||||||
fixtures := &Fixtures{
|
fixtures := &Fixtures{
|
||||||
Etcd: NewEtcdWithBinaryAndConfig(pathToEtcd, etcdConfig),
|
Etcd: NewEtcdWithBinaryAndConfig(pathToEtcd, etcdConfig),
|
||||||
APIServer: NewAPIServerWithBinary(pathToAPIServer, apiServerConfig),
|
APIServer: NewAPIServer(apiServerConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
fixtures.Config = FixturesConfig{
|
fixtures.Config = FixturesConfig{
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,9 @@ import (
|
||||||
|
|
||||||
var _ = Describe("Fixtures", func() {
|
var _ = Describe("Fixtures", func() {
|
||||||
It("can construct a properly wired Fixtures struct", func() {
|
It("can construct a properly wired Fixtures struct", func() {
|
||||||
f, err := NewFixtures("path to etcd", "path to apiserver")
|
f, err := NewFixtures("path to etcd")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(f.Etcd.(*Etcd).Path).To(Equal("path to etcd"))
|
Expect(f.Etcd.(*Etcd).Path).To(Equal("path to etcd"))
|
||||||
Expect(f.APIServer.(*APIServer).Path).To(Equal("path to apiserver"))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("with a properly configured set of Fixtures", func() {
|
Context("with a properly configured set of Fixtures", func() {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ func TestIntegration(t *testing.T) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultPathToEtcd string
|
defaultPathToEtcd string
|
||||||
defaultPathToApiserver string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = BeforeSuite(func() {
|
var _ = BeforeSuite(func() {
|
||||||
|
|
@ -27,17 +26,12 @@ var _ = BeforeSuite(func() {
|
||||||
Expect(ok).NotTo(BeFalse())
|
Expect(ok).NotTo(BeFalse())
|
||||||
defaultAssetsDir := filepath.Clean(filepath.Join(filepath.Dir(thisFile), "..", "assets", "bin"))
|
defaultAssetsDir := filepath.Clean(filepath.Join(filepath.Dir(thisFile), "..", "assets", "bin"))
|
||||||
defaultPathToEtcd = filepath.Join(defaultAssetsDir, "etcd")
|
defaultPathToEtcd = filepath.Join(defaultAssetsDir, "etcd")
|
||||||
defaultPathToApiserver = filepath.Join(defaultAssetsDir, "kube-apiserver")
|
|
||||||
|
|
||||||
if pathToBin, ok := os.LookupEnv("TEST_ETCD_BIN"); ok {
|
if pathToBin, ok := os.LookupEnv("TEST_ETCD_BIN"); ok {
|
||||||
defaultPathToEtcd = pathToBin
|
defaultPathToEtcd = pathToBin
|
||||||
}
|
}
|
||||||
if pathToBin, ok := os.LookupEnv("TEST_APISERVER_BIN"); ok {
|
|
||||||
defaultPathToApiserver = pathToBin
|
|
||||||
}
|
|
||||||
|
|
||||||
Expect(defaultPathToEtcd).NotTo(BeEmpty(), "Path to etcd cannot be empty, set $TEST_ETCD_BIN")
|
Expect(defaultPathToEtcd).NotTo(BeEmpty(), "Path to etcd cannot be empty, set $TEST_ETCD_BIN")
|
||||||
Expect(defaultPathToApiserver).NotTo(BeEmpty(), "Path to apiserver cannot be empty, set $TEST_APISERVER_BIN")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = AfterSuite(func() {
|
var _ = AfterSuite(func() {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ var _ = Describe("The Testing Framework", func() {
|
||||||
var err error
|
var err error
|
||||||
var fixtures *test.Fixtures
|
var fixtures *test.Fixtures
|
||||||
|
|
||||||
fixtures, err = test.NewFixtures(defaultPathToEtcd, defaultPathToApiserver)
|
fixtures, err = test.NewFixtures(defaultPathToEtcd)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("Starting all the fixture processes")
|
By("Starting all the fixture processes")
|
||||||
|
|
@ -63,7 +63,7 @@ var _ = Describe("The Testing Framework", func() {
|
||||||
|
|
||||||
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 fixtures", func(b Benchmarker) {
|
||||||
b.Time("lifecycle", func() {
|
b.Time("lifecycle", func() {
|
||||||
fixtures, err := test.NewFixtures(defaultPathToEtcd, defaultPathToApiserver)
|
fixtures, err := test.NewFixtures(defaultPathToEtcd)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
fixtures.Start()
|
fixtures.Start()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue