示例#1
0
func (s *TestSuite) TestHealth(c *C) {
	// when
	r, err := rest.MakeRequest("GET", fmt.Sprintf("http://%s/health", s.svc.Server.Bind), nil)

	// then
	c.Assert(err, Equals, nil)
	c.Assert(r.StatusCode, Equals, http.StatusOK)
}
// Client should return ErrStatusBadRequest if Id doesn't validate
// (not supported by client so pulled impl into test)
func (s *TestSuite) TestDeleteBdRequesta(c *C) {
	// when
	url := fmt.Sprintf("%s/location/%s", s.host, "asd")
	r, _ := rest.MakeRequest("DELETE", url, nil)
	err := rest.ProcessResponseEntity(r, nil, http.StatusNoContent)

	// then
	c.Assert(err, Equals, rest.ErrStatusBadRequest)
}
示例#3
0
func (c *LocationClient) DeleteLocation(id int) error {
	url := fmt.Sprintf("%s/location/%d", c.Host, id)
	r, err := rest.MakeRequest("DELETE", url, nil)
	if err != nil {
		return err
	}
	err = rest.ProcessResponseEntity(r, nil, http.StatusNoContent)
	return err
}
// Client should return ErrStatusBadRequest when id doesn't validate
// (not supported by client so pulled impl into test)
func (s *TestSuite) TestFindBadRequest(c *C) {

	// when
	url := fmt.Sprintf("%s/location/%s", s.host, "asd")
	r, err := rest.MakeRequest("GET", url, nil)
	err = rest.ProcessResponseEntity(r, nil, http.StatusOK)

	// then
	c.Assert(err, Equals, rest.ErrStatusBadRequest)
}
示例#5
0
func (c *ReportClient) FindAll() (Report, error) {
	var rep Report

	r, err := rest.MakeRequest("GET", fmt.Sprintf("http://%s/report", c.Address), nil)
	if err != nil {
		return rep, err
	}
	err = rest.ProcessResponseEntity(r, &rep, http.StatusOK)
	return rep, err
}
示例#6
0
func (c *ReportClient) GaugeSet(name string, n int64) error {
	g := &Gauge{Name: name, N: n}

	r, err := rest.MakeRequest("POST", fmt.Sprintf("http://%s/gauge", c.Address), g)
	if err != nil {
		return err
	}

	err = rest.ProcessResponseEntity(r, nil, http.StatusOK)
	return err
}
示例#7
0
func (c *ReportClient) CounterAdd(name string, n uint64) error {
	ctr := &Counter{Name: name, N: n}

	r, err := rest.MakeRequest("POST", fmt.Sprintf("http://%s/counter", c.Address), ctr)
	if err != nil {
		return err
	}

	err = rest.ProcessResponseEntity(r, nil, http.StatusOK)
	return err
}
示例#8
0
func (c *LocationClient) SaveLocation(toSave api.Location) (api.Location, error) {
	var location api.Location

	url := fmt.Sprintf("%s/location/%d", c.Host, toSave.Id)
	r, err := rest.MakeRequest("PUT", url, toSave)
	if err != nil {
		return location, err
	}
	err = rest.ProcessResponseEntity(r, &location, http.StatusOK)
	return location, err
}
示例#9
0
func (c *LocationClient) FindLocation(id int) (api.Location, error) {
	var location api.Location

	url := fmt.Sprintf("%s/location/%d", c.Host, id)
	r, err := rest.MakeRequest("GET", url, nil)
	if err != nil {
		return location, err
	}
	err = rest.ProcessResponseEntity(r, &location, http.StatusOK)
	return location, err
}
示例#10
0
func (c *LocationClient) FindAllLocations() ([]api.Location, error) {
	var locations []api.Location

	url := fmt.Sprintf("%s/location", c.Host)
	r, err := rest.MakeRequest("GET", url, nil)
	if err != nil {
		return locations, err
	}
	err = rest.ProcessResponseEntity(r, &locations, http.StatusOK)
	return locations, err
}
示例#11
0
func (c *WeatherClient) FindForLocation(city string, state string) (api.Conditions, error) {
	var cond api.Conditions

	url := fmt.Sprintf("%s%s,%s", UriString, city, state)
	r, err := rest.MakeRequest("GET", url, nil)
	if err != nil {
		return cond, err
	}
	err = rest.ProcessResponseEntity(r, &cond, http.StatusOK)
	return cond, err
}
示例#12
0
func (c *Client) Get(name string) (Package, error) {
	var p PackageWrapper
	url := fmt.Sprintf("https://packagist.org/packages/%s.json", name)

	r, err := rest.MakeRequest("GET", url, nil)
	if err != nil {
		return p.Package, err
	}
	err = rest.ProcessResponseEntity(r, &p, http.StatusOK)
	return p.Package, err
}
示例#13
0
func (c *TodoClient) Delete(id int) error {
	host, err := c.Lb.GetAddress(c.Address)
	if err != nil {
		return err
	}

	r, err := rest.MakeRequest("DELETE", fmt.Sprintf("http://%s/todo/%d", host, id), nil)
	if err != nil {
		return err
	}
	return rest.ProcessResponseEntity(r, nil, http.StatusNoContent)
}
示例#14
0
// Client should return ErrStatusConflict when id exists
// (not supported by client so pulled impl into test)
func (s *TestSuite) TestAddConflict(c *C) {
	// given
	locClient := client.LocationClient{Host: s.host}
	created, _ := locClient.AddLocation("Austin", "Texas")

	// when
	url := fmt.Sprintf("%s/location", s.host)
	r, _ := rest.MakeRequest("POST", url, created)
	err := rest.ProcessResponseEntity(r, nil, http.StatusCreated)

	// then
	c.Assert(err, Equals, rest.ErrStatusConflict)
}
示例#15
0
func (c *TodoClient) Find(id int) (*Todo, error) {
	var found *Todo
	host, err := c.Lb.GetAddress(c.Address)
	if err != nil {
		return found, err
	}

	r, err := rest.MakeRequest("GET", fmt.Sprintf("http://%s/todo/%d", host, id), nil)
	if err != nil {
		return found, err
	}
	err = rest.ProcessResponseEntity(r, &found, http.StatusOK)
	return found, err
}
示例#16
0
// Client should return ErrStatusBadRequest if Id doesn't validate
// (not supported by client so pulled impl into test)
func (s *TestSuite) TestSaveBadRequestFromId(c *C) {
	// given
	locClient := client.LocationClient{Host: s.host}

	location, _ := locClient.AddLocation("Austin", "Texas")

	// when
	url := fmt.Sprintf("%s/location/%s", s.host, "asd")
	r, err := rest.MakeRequest("GET", url, location)
	err = rest.ProcessResponseEntity(r, nil, http.StatusOK)

	// then
	c.Assert(err, Equals, rest.ErrStatusBadRequest)
}
示例#17
0
func (c *TodoClient) Save(todo *Todo) (*Todo, error) {
	var saved *Todo
	host, err := c.Lb.GetAddress(c.Address)
	if err != nil {
		return saved, err
	}

	r, err := rest.MakeRequest("PUT", fmt.Sprintf("http://%s/todo/%d", host, todo.Id), todo)
	if err != nil {
		return saved, err
	}
	err = rest.ProcessResponseEntity(r, &saved, http.StatusOK)
	return saved, err
}
示例#18
0
func (c *TodoClient) Add(content string) (*Todo, error) {
	var created *Todo
	host, err := c.Lb.GetAddress(c.Address)
	if err != nil {
		return created, err
	}
	todo := &Todo{Content: content, Status: "new"}

	r, err := rest.MakeRequest("POST", fmt.Sprintf("http://%s/todo", host), todo)
	if err != nil {
		return created, err
	}
	err = rest.ProcessResponseEntity(r, &created, http.StatusCreated)
	return created, err
}
示例#19
0
func (c *TodoClient) FindAll() ([]*Todo, error) {
	var todos []*Todo

	host, err := c.Lb.GetAddress(c.Address)
	if err != nil {
		return todos, err
	}

	r, err := rest.MakeRequest("GET", fmt.Sprintf("http://%s/todo", host), nil)
	if err != nil {
		return todos, err
	}
	err = rest.ProcessResponseEntity(r, &todos, http.StatusOK)
	return todos, err
}
示例#20
0
func (c *LocationClient) AddLocation(city string, state string) (api.Location, error) {
	var location api.Location

	newLocation := api.Location{
		City:  city,
		State: state,
	}

	url := fmt.Sprintf("%s/location", c.Host)
	r, err := rest.MakeRequest("POST", url, newLocation)
	if err != nil {
		return location, err
	}
	err = rest.ProcessResponseEntity(r, &location, http.StatusCreated)
	return location, err
}