예제 #1
0
파일: upload_test.go 프로젝트: OSBI/juju
func (s *UploadSuite) TestHandleRequestPending(c *gc.C) {
	content := "<some data>"
	res, _ := newResource(c, "spam", "a-user", content)
	res.PendingID = "some-unique-id"
	stored, _ := newResource(c, "spam", "", "")
	stored.PendingID = "some-unique-id"
	s.data.ReturnGetPendingResource = stored
	s.data.ReturnUpdatePendingResource = res
	uh := server.UploadHandler{
		Username: "******",
		Store:    s.data,
	}
	req, body := newUploadRequest(c, "spam", "a-service", content)
	req.URL.RawQuery += "&pendingid=some-unique-id"

	result, err := uh.HandleRequest(req)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "GetPendingResource", "UpdatePendingResource")
	s.stub.CheckCall(c, 0, "GetPendingResource", "a-service", "spam", "some-unique-id")
	s.stub.CheckCall(c, 1, "UpdatePendingResource", "a-service", "some-unique-id", "a-user", res.Resource, ioutil.NopCloser(body))
	c.Check(result, jc.DeepEquals, &api.UploadResult{
		Resource: api.Resource2API(res),
	})
}
예제 #2
0
파일: upload_test.go 프로젝트: OSBI/juju
func (s *UploadSuite) TestHandleRequestSetResourceFailure(c *gc.C) {
	content := "<some data>"
	stored, _ := newResource(c, "spam", "", "")
	s.data.ReturnGetResource = stored
	uh := server.UploadHandler{
		Username: "******",
		Store:    s.data,
	}
	req, _ := newUploadRequest(c, "spam", "a-service", content)
	failure := errors.New("<failure>")
	s.stub.SetErrors(nil, failure)

	_, err := uh.HandleRequest(req)

	c.Check(errors.Cause(err), gc.Equals, failure)
	s.stub.CheckCallNames(c, "GetResource", "SetResource")
}
예제 #3
0
파일: upload_test.go 프로젝트: bac/juju
func (s *UploadSuite) TestExtensionMismatch(c *gc.C) {
	content := "<some data>"

	// newResource returns a resource with a Path = name + ".tgz"
	res, _ := newResource(c, "spam", "a-user", content)
	stored, _ := newResource(c, "spam", "", "")
	s.data.ReturnGetResource = stored
	s.data.ReturnSetResource = res
	uh := server.UploadHandler{
		Username: "******",
		Store:    s.data,
	}
	req, _ := newUploadRequest(c, "spam", "a-application", content)
	req.Header.Set("Content-Disposition", "form-data; filename=different.ext")

	_, err := uh.HandleRequest(req)
	c.Assert(err, gc.ErrorMatches, `incorrect extension on resource upload "different.ext", expected ".tgz"`)
}
예제 #4
0
파일: upload_test.go 프로젝트: OSBI/juju
func (s *UploadSuite) TestHandleRequestOkay(c *gc.C) {
	content := "<some data>"
	res, _ := newResource(c, "spam", "a-user", content)
	stored, _ := newResource(c, "spam", "", "")
	s.data.ReturnGetResource = stored
	s.data.ReturnSetResource = res
	uh := server.UploadHandler{
		Username: "******",
		Store:    s.data,
	}
	req, body := newUploadRequest(c, "spam", "a-service", content)

	result, err := uh.HandleRequest(req)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "GetResource", "SetResource")
	s.stub.CheckCall(c, 0, "GetResource", "a-service", "spam")
	s.stub.CheckCall(c, 1, "SetResource", "a-service", "a-user", res.Resource, ioutil.NopCloser(body))
	c.Check(result, jc.DeepEquals, &api.UploadResult{
		Resource: api.Resource2API(res),
	})
}