// getAvailablePort returns a TCP port that is available for binding. func getAvailablePorts(count int) ([]int, error) { … } // NewTestConfig returns a configuration for an embedded etcd server. // The configuration is based on embed.NewConfig(), with the following adjustments: // - sets UnsafeNoFsync = true to improve test performance (only reasonable in a test-only // single-member server we never intend to restart or keep data from) // - uses free ports for client and peer listeners // - cleans up the data directory on test termination // - silences server logs other than errors func NewTestConfig(t testing.TB) *embed.Config { … } // RunEtcd starts an embedded etcd server with the provided config // (or NewTestConfig(t) if nil), and returns a client connected to the server. // The server is terminated when the test ends. func RunEtcd(t testing.TB, cfg *embed.Config) *kubernetes.Client { … }