當前位置: 首頁>>代碼示例>>Golang>>正文


Golang server.LegacyHTTPHandler類代碼示例

本文整理匯總了Golang中github.com/juju/juju/resource/api/server.LegacyHTTPHandler的典型用法代碼示例。如果您正苦於以下問題:Golang LegacyHTTPHandler類的具體用法?Golang LegacyHTTPHandler怎麽用?Golang LegacyHTTPHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了LegacyHTTPHandler類的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))},
	})
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:33,代碼來源:handler_test.go

示例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))},
	})
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:29,代碼來源:handler_test.go

示例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))},
	})
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:29,代碼來源:handler_test.go


注:本文中的github.com/juju/juju/resource/api/server.LegacyHTTPHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。