Пример #1
0
// 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)
}
Пример #2
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
}
Пример #3
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
}
Пример #4
0
// 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 *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
}
Пример #6
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
}
Пример #7
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
}
Пример #8
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
}
Пример #9
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
}
Пример #10
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
}
Пример #11
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
}
Пример #12
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)
}
Пример #13
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)
}
Пример #14
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)
}
Пример #15
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
}
Пример #16
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
}
Пример #17
0
func (c *Client) GetRepo(proj string, name string) (*Repo, error) {
	var repo Repo
	url := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s", c.Url, proj, name)

	r, err := c.makeRequest("GET", url, nil)
	if err != nil {
		return &repo, err
	}
	err = rest.ProcessResponseEntity(r, &repo, http.StatusOK)
	if err != nil {
		_, err := rest.ProcessResponseBytes(r, http.StatusNotFound)
		return nil, err
	}
	return &repo, err
}
Пример #18
0
func (c *Client) GetAllReposPage(proj string) ([]Repo, error) {
	var page RepoPage
	url := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos", c.Url, proj)

	r, err := c.makeRequest("GET", url, nil)
	if err != nil {
		return page.Values, err
	}
	err = rest.ProcessResponseEntity(r, &page, http.StatusOK)
	if err != nil {
		_, err := rest.ProcessResponseBytes(r, http.StatusNotFound)
		return nil, err
	}
	return page.Values, 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 *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
}
Пример #21
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
}
Пример #22
0
func (c *Client) CreateRepo(proj string, name string) (*Repo, error) {
	var repo Repo

	body := RepoConfig{Name: name, ScmId: "git", Forkable: true}

	url := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos", c.Url, proj)
	r, err := c.makeRequest("POST", url, body)
	if err != nil {
		return &repo, err
	}

	err = rest.ProcessResponseEntity(r, &repo, http.StatusCreated)
	if err != nil {
		b, _ := ioutil.ReadAll(r.Body)
		return nil, fmt.Errorf(string(b[:]))
	}
	return &repo, err
}