Example #1
0
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
}
Example #2
0
func NewConsulClient(opts Options) *api.Client {
	conf := api.DefaultConfig()
	if opts.Address != "" {
		conf.Address = opts.Address
	}
	if opts.Client != nil {
		conf.HttpClient = opts.Client
	}
	if opts.HTTPS {
		conf.Scheme = "https"
	}
	conf.Token = opts.Token
	if opts.WaitTime != 0 {
		conf.WaitTime = opts.WaitTime
	}

	// error is always nil
	ret, _ := api.NewClient(conf)
	return ret
}