本文整理汇总了Golang中github.com/juju/juju/resource/api/server.UploadHandler.HandleRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang UploadHandler.HandleRequest方法的具体用法?Golang UploadHandler.HandleRequest怎么用?Golang UploadHandler.HandleRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/resource/api/server.UploadHandler
的用法示例。
在下文中一共展示了UploadHandler.HandleRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestHandleRequestPending
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: "a-user",
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: TestHandleRequestSetResourceFailure
func (s *UploadSuite) TestHandleRequestSetResourceFailure(c *gc.C) {
content := "<some data>"
stored, _ := newResource(c, "spam", "", "")
s.data.ReturnGetResource = stored
uh := server.UploadHandler{
Username: "a-user",
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: TestExtensionMismatch
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: "a-user",
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: TestHandleRequestOkay
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: "a-user",
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),
})
}