Commit Graph

69 Commits

Author SHA1 Message Date
Hannes Hörl a49601db63 Remove PortFinder, use AddressManager
Nothing uses the PortFinder anymore. We can now remove the PortFinder,
and rename the files to make clear AddressManager is now the thing to
use.
2017-12-13 13:59:04 +00:00
Hannes Hörl 0683d7977a Test APIServer's CertDirManager 2017-12-13 13:59:02 +00:00
Hannes Hörl 0aa877d964 Remove EtcdConfig
Using the AddressManager in Etcd removes the need for EtcdConfig.
2017-12-13 13:58:55 +00:00
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 d4e9e90d86 Move etcd path logic from constructor to Start()
This means that if you want to customize the path to your etcd, instead
of doing `etcd.Path = "/my/path"` you should do:

```
etcd.PathFinder = func(_ string) string {
  return "/my/path"
}
```

The advantage of this is that we move logic out of the constructor, so
we need less crazy dependancy injection logic in our tests, and we get
closer to being able to use the 0-value Etcd struct.
2017-12-11 17:18:25 +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 1defd3c52e Make Fixtures constructor take 0 args
This is a natural consequence of cleaning up after the "APIServer is
responsible for Etcd" refactor.
2017-12-11 12:09:27 +00:00
Hannes Hörl fe4e62dc59 Remove EtcdURL from APIServer Config 2017-12-11 12:02:07 +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 a86b2f83fe Bugfix for BinPathFinder
We now sanitize the binary names from which we construct environment
variables to query for custom binary paths. This means we can now
customize the apiserver binary path with $TEST_ASSET_KUBE_APISERVER
2017-12-08 16:22:46 +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 3bdc1f4b9b Add a new default constructor for Etcd
- The default constructor for Etcd uses the DefaultBinPathFinder and the
  default EtcdConfig constructor internally
- The Fixtures still use the old constructor, which means it passes in a
  binary path and an EtcdConfig
2017-12-08 14:32:53 +00:00
Hannes Hörl 84e6727884 Add a default constructor for EtcdConfig 2017-12-08 14:13:56 +00:00
Hannes Hörl 08f495a8ee Add a simple Port Finder 2017-12-08 14:08:38 +00:00
Hannes Hörl a4b6e08b30 Add a simple Binary Path Finder 2017-12-08 10:59:29 +00:00
Hannes Hörl 4d9d2ce534 Check errors even in defer blocks 2017-12-07 16:13:30 +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 15d507fc83 Change overrides for test fixture paths
One can override the paths to the binaries (etcd, APIServer) to test
against by setting the environment variables
- TEST_ETCD_BIN
- TEST_APISERVER_BIN
2017-12-06 14:46:02 +00:00
Hannes Hörl eee6a20808 Use fakes to get listening URLs for the fixtures 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 1513093427 Integrate test framework tests properly
The test framework can now run properly with `go test` and we can remove
- our test wrapper
- special handling of tests for the test framewoek
2017-12-06 14:46:02 +00:00
Hannes Hörl 98faa6a9dc Change handling of default test assets location
If $KUBE_ASSETS_DIR is set, we use that and try to run the binaries from
within that directory.
If it is not set, we try to determine the assets directory as a relative
path to the test suite.
2017-12-06 14:46:02 +00:00
Hannes Hörl 2d275663fe Use the exposed configuration of the fixtures
The fixtures now exposes the URL the API Server is listening on. We can
get this with from `Fixtures.Config.APIServerURL`.

When we start our client program in the test, we pass that API Server
URL in via a command line flag.
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 1923179219 Use a fake datadir manager in etcd tests 2017-12-04 17:32:03 +00:00
Hannes Hörl 9fa768de26 Refactor Etcd to use a simpler CLI Session
We introduced a SimpleSession interface which allows us to have better
fakes for unit testing. This Session is implemented by *gexec.Session.
2017-12-04 12:19:59 +00:00
Hannes Hörl 84b1e9b91f Rename test suites 2017-12-04 11:32:26 +00:00
Hannes Hörl 4d4026f5b0 Make the framework test bash3 compatible 2017-11-29 16:24:37 +00:00
Hannes Hörl ccb54d246a Make `pre-commit.sh` work with the test framework
Eventually we want our framework to work nicely with just `go test`. To
get there we need to
- inject KUBE_ASSETS_DIR
- make the framework work when run multiple times in parallel (port
  collitions, expose bound ports the the subject under test, ...)

We decided to make sure our tests are run in sequence (and not in
parallel to any other thing using etcd, for that matter) by making this
explicit in the `pre-commit.sh` - for now.

As soon as we are there, we can rollback the change to the
`pre-commit.sh` end have the test framework be tested the same as
everything else.

[#153248975]
2017-11-29 15:20:41 +00:00
Hannes Hörl 849d4f9e39 Switch to repo-global vendoring, move dependencies
Actually now put the dependencies into the global `vendor` direcotry.
2017-11-29 12:34:54 +00:00
Hannes Hörl d89f4c1cee Switch to repo-global vendoring 2017-11-29 12:30:11 +00:00
Hannes Hörl d88f71cc27 Change `.gitignore` strategy
- Use a `.gitignore` local to the test framework
- Remove some local only things (`.idea`) from the `.gitignore` and push
that to `.git/info/exclude`
2017-11-29 12:08:31 +00:00
Hannes Hörl c4e57df807 Create nicer names for temporary directories
[#153246098]
2017-11-29 12:08:31 +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 ff9f027096 Drop privilages before running tests in CI 2017-11-29 12:08:31 +00:00
Gareth Smith f5b7280242 Make Etcd's DataDirManager interface private 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
Hannes Hörl 63de385c65 Add test option to run performance tests
Performance tests are now skipped by default, but run in CI.
2017-11-29 12:08:31 +00:00
Gareth Smith 8523ad31f8 Start the fixture processes in parallel 2017-11-29 12:08:31 +00:00
Gareth Smith e2a217b37b Track the time it takes to start&stop the fixtures 2017-11-29 12:08:31 +00:00
Gareth Smith eca5aace13 Add dependencies
As a separate commit, to make review easier.
2017-11-29 12:08:31 +00:00
Gareth Smith 11eab48530 Implement first command talking to the APIServer
We use the standard go client for kubernetes `client-go`. To vendor it
and all its denpendecies we use
```
dep ensure -add k8s.io/client-go@5.0.0
```

We create a new cobra command with
```
cobra add listPods
```
Note: The new command in cmd/listPods.go uses [the "magic" function
init()](https://golang.org/ref/spec#Package_initialization) to register
itself.
2017-11-29 12:08:29 +00:00
Gareth Smith 2e5a83252e Remove {Etcd,APIServer}StartStopper interfaces
... as they have been unified into the FixtureProcess interface and thus
they are not needed anymore.
2017-11-29 12:08:29 +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 5d670c4625 Refactor away anonymous functions in integration test 2017-11-29 12:08:29 +00:00