Beispiel #1
0
func (s *DeploymentsApiRoutesTestSuite) TestCreateDeployments(c *C) {
	url := path.Join(s.apiPrefix, "repos", s.namespace, "deployments")
	method := "POST"

	for _, i := range s.deployments {
		s.response = httptest.NewRecorder()
		d, _ := json.Marshal(i)
		request, err := http.NewRequest(method, url, bytes.NewBuffer(d))

		if err != nil {
			c.Fatal(err)
		}

		// Make the call
		s.router.ServeHTTP(s.response, request)
		c.Assert(s.response.Code, Equals, http.StatusCreated)
		body := s.response.Body.Bytes()

		deploy := data.Deployment{}
		json.Unmarshal(body, &deploy)

		c.Assert(deploy.Sha, Equals, i.Sha)
		c.Assert(deploy.Ref, Equals, i.Ref)
		c.Assert(deploy.Task, Equals, i.Task)
		c.Assert(deploy.Environment, Equals, i.Environment)
	}

	deps, _ := data.ListDeployments(s.deployments[0].Namespace)
	c.Assert(len(deps), Equals, len(s.deployments))

}
Beispiel #2
0
func DeployListHandler(w http.ResponseWriter, r *http.Request) {
	params := mux.Vars(r)
	logHandler(r, "DeployListHandler", params, r.URL.Query())
	namespace := strings.Join([]string{params["owner"], params["repo"]}, "/")

	deployments, err := data.ListDeployments(namespace)
	if err != nil {
		log.Error("Error processing deployments")
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	b, err := json.Marshal(deployments)

	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Error("Error Marshalling json")
		return
	}

	writeJson(w, b, nil, http.StatusOK)
}