Beispiel #1
0
func (s *S) TestRemoveRepositoryShouldRemoveFromDB(c *gocheck.C) {
	r, err := repository.New("myRepo", []string{"pippin"}, true)
	c.Assert(err, gocheck.IsNil)
	url := fmt.Sprintf("repository/%s/?:name=%s", r.Name, r.Name)
	request, err := http.NewRequest("DELETE", url, nil)
	c.Assert(err, gocheck.IsNil)
	recorder := httptest.NewRecorder()
	RemoveRepository(recorder, request)
	err = db.Session.Repository().Find(bson.M{"_id": r.Name}).One(&r)
	c.Assert(err, gocheck.ErrorMatches, "^not found$")
}
Beispiel #2
0
func NewRepository(w http.ResponseWriter, r *http.Request) {
	var repo repository.Repository
	if err := parseBody(r.Body, &repo); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	rep, err := repository.New(repo.Name, repo.Users, repo.IsPublic)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	fmt.Fprintf(w, "Repository \"%s\" successfully created\n", rep.Name)
}
Beispiel #3
0
func (s *S) TestRemoveRepository(c *gocheck.C) {
	r, err := repository.New("myRepo", []string{"pippin"}, true)
	c.Assert(err, gocheck.IsNil)
	url := fmt.Sprintf("repository/%s/?:name=%s", r.Name, r.Name)
	request, err := http.NewRequest("DELETE", url, nil)
	c.Assert(err, gocheck.IsNil)
	recorder := httptest.NewRecorder()
	RemoveRepository(recorder, request)
	c.Assert(recorder.Code, gocheck.Equals, 200)
	b, err := ioutil.ReadAll(recorder.Body)
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(b), gocheck.Equals, "Repository \"myRepo\" successfully removed\n")
}
Beispiel #4
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)
}