func initTestServer(t *testing.T) (*testutil.TestServer, *api.Client) { if testing.Short() { t.Skip("skipping test dependent on consul because of short mode") } defer func() { // if consul is not in the $PATH, NewTestServer will skip the test, // which should be treated as an error if t.Skipped() { t.Error("failing skipped test") } }() server := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) { ports := getPorts(t, 6) c.Ports = &testutil.TestPortConfig{ DNS: ports[0], HTTP: ports[1], RPC: ports[2], SerfLan: ports[3], SerfWan: ports[4], Server: ports[5], } }) client, err := api.NewClient(&api.Config{ Address: server.HTTPAddr, }) if err != nil { t.Fatal(err) } return server, client }
func makeStore(t *testing.T) (kp.Store, *testutil.TestServer) { if testing.Short() { t.Skip("skipping test dependendent on consul because of short mode") } // testutil.NewTestServerConfig will skip the test if "consul" isn't in the system path. // We'd rather the test fail. defer func() { if t.Skipped() { t.Fatalf("test skipped by testutil package") } }() // Create server server := testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) { // consul output in test output is noisy c.Stdout = ioutil.Discard c.Stderr = ioutil.Discard // If ports are left to their defaults, this test conflicts // with the test consul servers in pkg/kp var offset uint64 idx := int(atomic.AddUint64(&offset, 1)) c.Ports = &testutil.TestPortConfig{ DNS: 26000 + idx, HTTP: 27000 + idx, RPC: 28000 + idx, SerfLan: 29000 + idx, SerfWan: 30000 + idx, Server: 31000 + idx, } }) client := kp.NewConsulClient(kp.Options{ Address: server.HTTPAddr, }) store := kp.NewConsulStore(client) return store, server }
func makeClientWithConfig( t *testing.T, cb1 configCallback, cb2 testutil.ServerConfigCallback) (*Client, *testutil.TestServer) { // Make client config conf := DefaultConfig() if cb1 != nil { cb1(conf) } // Create server server := testutil.NewTestServerConfig(t, cb2) conf.Address = server.HTTPAddr // Create client client, err := NewClient(conf) if err != nil { t.Fatalf("err: %v", err) } return client, server }