Commit Graph

19 Commits

Author SHA1 Message Date
Hannes Hörl ffa8ee46e5 Give APIServer constructor sane defaults
The APIServer constructor previously required careful configuration. Now
it takes no arguments, and gives you an APIServer that you can
`.Start()`. If you want to configure it, you still can. For example, you
can set the environment variable `TEST_ASSET_KUBE_APISERVER` to the path
to your apiserver binary, or you can override the PathFinder in go code:

```
myAPIServer := test.NewAPIServer()
myAPIServer.PathFinder = func(_ string) string {
  return "/path/to/my/apiserver/binary"
}
```

Previously the responsibility of choosing a port that the APIServer
could listen on was left to the caller. Now APIServer delegates that
responsibility to an AddressManager. By default you get a random unused
port on localhost. If you want to customize that behaviour, you can
overwrite the AddressManager:

```
myAPIServer := test.NewAPIServer()
myAPIServer.AddressManager = myAddressManager
```

If this is a common request, then in future we might provide some common
custom AddressManagers.
2017-12-12 16:50:23 +00:00
Hannes Hörl 657963b319 Make APIServer manage its own port allocations
This means we will no longer need to pass a free port into the APIServer
constructor.
2017-12-12 15:46:53 +00:00
Hannes Hörl d62ff04228 Move APIServer path logic into Start()
Same as in previous commit for Etcd ( d4e9e90d86 )
2017-12-12 11:11:02 +00:00
Hannes Hörl 85ac9f5969 Expose APIServers coordinates via APIServerURL()
Instead of exposing client configuration via the Fixtures struct, we now
expose the APIServer's coordinates via a method on Fixtures.
2017-12-11 13:54:52 +00:00
Hannes Hörl b406414c2a Make ApiServer manage Etcd
Everything now works pretty much like before, so we're not yet feeling a
lot of the benefit. Still to do:

- Remove all vestiges of Etcd config etc from the Fixtures struct
- Remove duplicated config
- Make Fixtures and APIServer constructors take 0 params
2017-12-11 11:55:23 +00:00
Hannes Hörl ad04fd8972 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.
2017-12-08 16:01:19 +00:00
Hannes Hörl e6b042840b Add APIServer constructor with default binary path 2017-12-08 15:59:49 +00:00
Hannes Hörl 5afb9ee6cc Validate configs
Brings in github.com/asaskevich/govalidator
2017-12-06 14:46:02 +00:00
Hannes Hörl 819ad8519f Move logic back into fixtures constructor
- Introduce a type for the fixture process configuration
2017-12-06 14:46:02 +00:00
Hannes Hörl de3af899fc Refactor FixtureProcesses
- Remove the logic from the constructors
- Have start take a configuration map for the fixture processes
- Move the testing on open ports closer to the actual start
2017-12-06 14:46:02 +00:00
Hannes Hörl e8c6a13d49 Configure fixture processes with ports to listen on
- APIServer & Etcd get configured, from the outside, on which ports to
  listen on
- Configuration, the subjects under test might be interested in, is
  exposed by Fixtures.Config

Hint: Before we start any process, we get a random port and check if
that random port is acutally free to bind to. As it takes some time
until we actually start anything, we might run into cases, where another
process binds to that port while we are starting up. Even if we do the
port checking closer to actually binding, we still have the same issue.
For now, however, we take that risk - if we run into problems with that,
we are open to refactor that.
2017-12-06 14:46:02 +00:00
Hannes Hörl d9268017e3 Refactor APIServer
- Use a fake certificate directory manager
- Use a simpler CLI Session
2017-12-04 17:43:57 +00:00
Hannes Hörl b7cfe0f868 Update comments on Start/Stop of the processes
[#153243856]
2017-11-29 12:08:31 +00:00
Gareth Smith 7df93be2ab Use a temporary directory for the APIServer's certs
While doing that we found that we needed to refactor the fakes to handle
command line arguments which are not known up front; we do this by using
regular expresseions.
2017-11-29 12:08:31 +00:00
Gareth Smith d6f4cc6054 Refactor Etcd and APIServer, esp. Start() and Stop()
- Start() should only return when the process is actually up and
  listening
- It may take some time to tear down a process, so we increased the
  timeout for Stop() (to some random number)
- We make sure Std{Out,Err} is properly initialized, we should not rely
  on Ginkgo/Gomega to do that for us
2017-11-29 12:08:29 +00:00
Gareth Smith 940bec8b1c Refactor APIServer
- Store stdout,stderr in private buffers
- Configure the etcURL on construction instead of at start time
2017-11-29 12:08:29 +00:00
Gareth Smith 8a92d310ba Make Stop() wait for the processes to exit 2017-11-29 12:08:29 +00:00
Gareth Smith fc5d4050b1 Add Fixtures struct, which can start+stop everything
Create a new set of test fixtures by doing:

```
f := test.NewFixtures("/path/to/etcd", "/path/to/apiserver")
```

Before running your integration tests, start all your fixtures:

```
err := f.Start()
Expect(err).NotTo(HaveOccurred())
```

Now that you have started your etcd and apiserver, you'll find the
apiserver listening locally on the default port. When you're done with
your testing, stop and clean up:

```
err := f.Stop()
Expect(err).NotTo(HaveOccurred())
```
2017-11-29 12:08:29 +00:00
Gareth Smith 9d271bf497 Add apiserver launcher to test framework
To start an apiserver:

```
apiServer := APIServer{Path: "/path/to/my/apiserver/binary"}
session, err := apiServer.Start("tcp://whereever.is.my.etcd:port")
Expect(err).NotTo(HaveOccurred())
```

When you're done testing against that apiserver:

```
session.Terminate().Wait()
```

...or if you prefer:

```
gexec.Terminate()
```

...which will terminate not only this apiserver, but also all other
command sessions you started in this test.
2017-11-29 12:08:29 +00:00