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) }
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) }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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) }
// 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) }
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 }
// 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) }
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 }
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 }
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 }
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 }