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


Golang server.UploadHandler類代碼示例

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


在下文中一共展示了UploadHandler類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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),
	})
}
開發者ID:OSBI,項目名稱:juju,代碼行數:25,代碼來源:upload_test.go

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

示例3: 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")
}
開發者ID:OSBI,項目名稱:juju,代碼行數:14,代碼來源:upload_test.go

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

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

示例6: 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")
}
開發者ID:OSBI,項目名稱:juju,代碼行數:17,代碼來源:upload_test.go

示例7: 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"`)
}
開發者ID:bac,項目名稱:juju,代碼行數:18,代碼來源:upload_test.go

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

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

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


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