本文整理汇总了Golang中github.com/juju/juju/resource/api/server.LegacyHTTPHandler.ServeHTTP方法的典型用法代码示例。如果您正苦于以下问题:Golang LegacyHTTPHandler.ServeHTTP方法的具体用法?Golang LegacyHTTPHandler.ServeHTTP怎么用?Golang LegacyHTTPHandler.ServeHTTP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/resource/api/server.LegacyHTTPHandler
的用法示例。
在下文中一共展示了LegacyHTTPHandler.ServeHTTP方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestServeHTTPPutSuccess
func (s *LegacyHTTPHandlerSuite) TestServeHTTPPutSuccess(c *gc.C) {
s.result.Resource.Name = "spam"
expected, err := json.Marshal(s.result)
c.Assert(err, jc.ErrorIsNil)
s.username = "youknowwho"
handler := server.LegacyHTTPHandler{
Connect: s.connect,
HandleUpload: s.handleUpload,
}
s.req.Method = "PUT"
copied := *s.req
req := &copied
handler.ServeHTTP(s.resp, req)
s.stub.CheckCallNames(c,
"Connect",
"HandleUpload",
"Header",
"Header",
"WriteHeader",
"Write",
)
s.stub.CheckCall(c, 0, "Connect", req)
s.stub.CheckCall(c, 1, "HandleUpload", "youknowwho", s.data, req)
s.stub.CheckCall(c, 4, "WriteHeader", http.StatusOK)
s.stub.CheckCall(c, 5, "Write", string(expected))
c.Check(req, jc.DeepEquals, s.req) // did not change
c.Check(s.header, jc.DeepEquals, http.Header{
"Content-Type": []string{"application/json"},
"Content-Length": []string{fmt.Sprint(len(expected))},
})
}
示例2: TestServeHTTPConnectFailure
func (s *LegacyHTTPHandlerSuite) TestServeHTTPConnectFailure(c *gc.C) {
s.username = "youknowwho"
handler := server.LegacyHTTPHandler{
Connect: s.connect,
HandleUpload: s.handleUpload,
}
copied := *s.req
req := &copied
failure, expected := apiFailure(c, "<failure>", "")
s.stub.SetErrors(failure)
handler.ServeHTTP(s.resp, req)
s.stub.CheckCallNames(c,
"Connect",
"Header",
"Header",
"WriteHeader",
"Write",
)
s.stub.CheckCall(c, 0, "Connect", req)
s.stub.CheckCall(c, 3, "WriteHeader", http.StatusInternalServerError)
s.stub.CheckCall(c, 4, "Write", expected)
c.Check(req, jc.DeepEquals, s.req) // did not change
c.Check(s.header, jc.DeepEquals, http.Header{
"Content-Type": []string{"application/json"},
"Content-Length": []string{strconv.Itoa(len(expected))},
})
}
示例3: TestServeHTTPUnsupportedMethod
func (s *LegacyHTTPHandlerSuite) TestServeHTTPUnsupportedMethod(c *gc.C) {
s.username = "youknowwho"
handler := server.LegacyHTTPHandler{
Connect: s.connect,
HandleUpload: s.handleUpload,
}
s.req.Method = "POST"
copied := *s.req
req := &copied
_, expected := apiFailure(c, `unsupported method: "POST"`, params.CodeMethodNotAllowed)
handler.ServeHTTP(s.resp, req)
s.stub.CheckCallNames(c,
"Connect",
"Header",
"Header",
"WriteHeader",
"Write",
)
s.stub.CheckCall(c, 0, "Connect", req)
s.stub.CheckCall(c, 3, "WriteHeader", http.StatusMethodNotAllowed)
s.stub.CheckCall(c, 4, "Write", expected)
c.Check(req, jc.DeepEquals, s.req) // did not change
c.Check(s.header, jc.DeepEquals, http.Header{
"Content-Type": []string{"application/json"},
"Content-Length": []string{strconv.Itoa(len(expected))},
})
}