示例#1
0
func (s *S) TestRenameRepository(c *gocheck.C) {
	r, err := repository.New("raising", []string{"*****@*****.**"}, true)
	c.Assert(err, gocheck.IsNil)
	url := fmt.Sprintf("/repository/%s/?:name=%s", r.Name, r.Name)
	body := strings.NewReader(`{"name":"freedom"}`)
	request, err := http.NewRequest("PUT", url, body)
	c.Assert(err, gocheck.IsNil)
	recorder := httptest.NewRecorder()
	RenameRepository(recorder, request)
	c.Assert(recorder.Code, gocheck.Equals, http.StatusOK)
	_, err = repository.Get("raising")
	c.Assert(err, gocheck.NotNil)
	r.Name = "freedom"
	repo, err := repository.Get("freedom")
	c.Assert(err, gocheck.IsNil)
	c.Assert(repo, gocheck.DeepEquals, *r)
}
示例#2
0
func GetRepository(w http.ResponseWriter, r *http.Request) {
	repo, err := repository.Get(r.URL.Query().Get(":name"))
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	out, err := json.Marshal(&repo)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Write(out)
}
示例#3
0
func updateRepository(w http.ResponseWriter, r *http.Request) {
	name := r.URL.Query().Get(":name")
	repo, err := repository.Get(name)
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	defer r.Body.Close()
	err = parseBody(r.Body, &repo)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}
	err = repository.Update(name, repo)
	if err != nil && err.Error() == "not found" {
		http.Error(w, err.Error(), http.StatusNotFound)
	} else if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}