Beispiel #1
0
func createRouter(routerName, configPrefix string) (router.Router, error) {
	apiUrl, err := config.GetString(configPrefix + ":api-url")
	if err != nil {
		return nil, err
	}
	scheduler, err := config.GetString(configPrefix + ":scheduler")
	if err != nil {
		scheduler = "rr"
	}
	mode, err := config.GetString(configPrefix + ":mode")
	if err != nil {
		mode = "nat"
	}
	client := fusisApi.NewClient(apiUrl)
	client.HttpClient = tsuruNet.Dial5Full60ClientNoKeepAlive
	r := &fusisRouter{
		apiUrl:    apiUrl,
		client:    client,
		proto:     "tcp",
		port:      80,
		scheduler: scheduler,
		mode:      mode,
	}
	return r, nil
}
Beispiel #2
0
func TestClientGetServicesError(t *testing.T) {
	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(`{"error": "any error"}`))
	}))
	defer srv.Close()
	cli := api.NewClient(srv.URL)
	_, _, err := cli.GetServices()
	assert.Equal(t, err.Error(), fmt.Sprintf("GET %s/services: 500 any error", srv.URL))
}
Beispiel #3
0
func TestClientGetServicesEmpty(t *testing.T) {
	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`[]`))
	}))
	defer srv.Close()
	cli := api.NewClient(srv.URL)
	result, _, err := cli.GetServices()
	assert.Nil(t, err)
	assert.Equal(t, []types.Service{}, result)
}
Beispiel #4
0
func TestClientGetServices(t *testing.T) {
	var req *http.Request
	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		req = r
		w.Write([]byte(`[{"name": "name1"}, {"name": "name2"}]`))
	}))
	defer srv.Close()
	cli := api.NewClient(srv.URL)
	result, _, err := cli.GetServices()
	assert.Nil(t, err)
	assert.Equal(t, []types.Service{
		{Name: "name1"},
		{Name: "name2"},
	}, result)

	assert.Equal(t, req.Method, "GET")
	assert.Equal(t, req.URL.Path, "/services")
}
Beispiel #5
0
func TestNewClient(t *testing.T) {
	cli := api.NewClient("myaddr")
	assert.NotNil(t, cli)
	assert.Equal(t, cli.Addr, "myaddr")
	assert.NotNil(t, cli.HttpClient)
}