本文整理汇总了Golang中github.com/juju/juju/resource/api/server.UploadHandler.ReadResource方法的典型用法代码示例。如果您正苦于以下问题:Golang UploadHandler.ReadResource方法的具体用法?Golang UploadHandler.ReadResource怎么用?Golang UploadHandler.ReadResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/resource/api/server.UploadHandler
的用法示例。
在下文中一共展示了UploadHandler.ReadResource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestReadResourceBadContentType
func (s *UploadSuite) TestReadResourceBadContentType(c *gc.C) {
uh := server.UploadHandler{
Username: "a-user",
Store: s.data,
}
req, _ := newUploadRequest(c, "spam", "a-service", "<some data>")
req.Header.Set("Content-Type", "text/plain")
_, err := uh.ReadResource(req)
c.Check(err, gc.ErrorMatches, "unsupported content type .*")
s.stub.CheckNoCalls(c)
}
示例2: TestReadResourceGetResourceFailure
func (s *UploadSuite) TestReadResourceGetResourceFailure(c *gc.C) {
uh := server.UploadHandler{
Username: "a-user",
Store: s.data,
}
req, _ := newUploadRequest(c, "spam", "a-service", "<some data>")
failure := errors.New("<failure>")
s.stub.SetErrors(failure)
_, err := uh.ReadResource(req)
c.Check(errors.Cause(err), gc.Equals, failure)
s.stub.CheckCallNames(c, "GetResource")
}
示例3: TestReadResourceBadSize
func (s *UploadSuite) TestReadResourceBadSize(c *gc.C) {
stored, _ := newResource(c, "spam", "", "")
s.data.ReturnGetResource = stored
uh := server.UploadHandler{
Username: "a-user",
Store: s.data,
}
req, _ := newUploadRequest(c, "spam", "a-service", "<some data>")
req.Header.Set("Content-Length", "should-be-an-int")
_, err := uh.ReadResource(req)
c.Check(err, gc.ErrorMatches, "invalid size.*")
s.stub.CheckNoCalls(c)
}
示例4: TestReadResourceBadFingerprint
func (s *UploadSuite) TestReadResourceBadFingerprint(c *gc.C) {
stored, _ := newResource(c, "spam", "", "")
s.data.ReturnGetResource = stored
uh := server.UploadHandler{
Username: "a-user",
Store: s.data,
}
req, _ := newUploadRequest(c, "spam", "a-application", "<some data>")
req.Header.Set("Content-SHA384", "bogus")
_, err := uh.ReadResource(req)
c.Check(err, gc.ErrorMatches, "invalid fingerprint.*")
s.stub.CheckNoCalls(c)
}
示例5: TestReadResourceOkay
func (s *UploadSuite) TestReadResourceOkay(c *gc.C) {
content := "<some data>"
expected, _ := newResource(c, "spam", "a-user", content)
stored, _ := newResource(c, "spam", "", "")
s.data.ReturnGetResource = stored
uh := server.UploadHandler{
Username: "a-user",
Store: s.data,
}
req, body := newUploadRequest(c, "spam", "a-service", content)
uploaded, err := uh.ReadResource(req)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "GetResource")
s.stub.CheckCall(c, 0, "GetResource", "a-service", "spam")
c.Check(uploaded, jc.DeepEquals, &server.UploadedResource{
Service: "a-service",
Resource: expected.Resource,
Data: ioutil.NopCloser(body),
})
}
示例6: TestReadResourcePending
func (s *UploadSuite) TestReadResourcePending(c *gc.C) {
content := "<some data>"
expected, _ := newResource(c, "spam", "a-user", content)
stored, _ := newResource(c, "spam", "", "")
s.data.ReturnGetPendingResource = stored
uh := server.UploadHandler{
Username: "a-user",
Store: s.data,
}
req, body := newUploadRequest(c, "spam", "a-application", content)
req.URL.RawQuery += "&pendingid=some-unique-id"
uploaded, err := uh.ReadResource(req)
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "GetPendingResource")
s.stub.CheckCall(c, 0, "GetPendingResource", "a-application", "spam", "some-unique-id")
c.Check(uploaded, jc.DeepEquals, &server.UploadedResource{
Service: "a-application",
PendingID: "some-unique-id",
Resource: expected.Resource,
Data: ioutil.NopCloser(body),
})
}