Example #1
0
func newTestAPIServer() *testAPIServer {
	etcd := newFakeEtcd()
	httpListener, _, _ := newHTTPListener(etcd)
	tcpListener, _, _ := newTCPListener(etcd)
	r := &Router{
		HTTP: httpListener,
		TCP:  tcpListener,
	}
	ts := &testAPIServer{
		Server:    httptest.NewServer(apiHandler(r)),
		listeners: []Listener{r.HTTP, r.TCP},
	}

	discoverd := newFakeDiscoverd()
	discoverd.Register("strowger-api", ts.Listener.Addr().String())
	ts.Client = client.NewWithDiscoverd("", discoverd)
	return ts
}
Example #2
0
func newTestAPIServer(t etcdrunner.TestingT) *testAPIServer {
	ec, killEtcd := newEtcd(t)
	dc, killDiscoverd := newDiscoverd(t)

	httpListener, _ := newHTTPListenerClients(t, ec, dc)
	tcpListener, _ := newTCPListenerClients(t, ec, dc)
	r := &Router{
		HTTP: httpListener,
		TCP:  tcpListener,
	}
	ts := &testAPIServer{
		Server:    httptest.NewServer(apiHandler(r)),
		listeners: []Listener{r.HTTP, r.TCP},
		cleanup:   []func(){killEtcd, killDiscoverd},
	}

	discoverd := newFakeDiscoverd()
	discoverd.Register("router-api", ts.Listener.Addr().String())
	ts.Client = client.NewWithDiscoverd("", discoverd)
	return ts
}