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


Golang resourcetesting.NewResource函數代碼示例

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


在下文中一共展示了NewResource函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestGetResourceInfoOkay

func (s *UnitFacadeSuite) TestGetResourceInfoOkay(c *gc.C) {
	opened1 := resourcetesting.NewResource(c, s.stub, "spam", "a-application", "some data")
	res1 := opened1.Resource
	opened2 := resourcetesting.NewResource(c, s.stub, "eggs", "a-application", "other data")
	res2 := opened2.Resource
	store := &stubUnitDataStore{Stub: s.stub}
	store.ReturnListResources = resource.ServiceResources{
		Resources: []resource.Resource{res1, res2},
	}
	uf := server.UnitFacade{DataStore: store}

	results, err := uf.GetResourceInfo(private.ListResourcesArgs{
		ResourceNames: []string{"spam", "eggs"},
	})
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "ListResources")
	c.Check(results, jc.DeepEquals, private.ResourcesResult{
		Resources: []private.ResourceResult{{
			Resource: api.Resource2API(res1),
		}, {
			Resource: api.Resource2API(res2),
		}},
	})
}
開發者ID:bac,項目名稱:juju,代碼行數:25,代碼來源:unitfacade_test.go

示例2: newPersistenceResource

func newPersistenceResource(c *gc.C, serviceID, name string) (storedResource, resourceDoc) {
	content := name
	opened := resourcetesting.NewResource(c, nil, name, serviceID, content)
	res := opened.Resource

	stored := storedResource{
		Resource:    res,
		storagePath: "application-" + serviceID + "/resources/" + name,
	}

	doc := resourceDoc{
		DocID:         "resource#" + res.ID,
		ID:            res.ID,
		ApplicationID: res.ApplicationID,

		Name:        res.Name,
		Type:        res.Type.String(),
		Path:        res.Path,
		Description: res.Description,

		Origin:      res.Origin.String(),
		Revision:    res.Revision,
		Fingerprint: res.Fingerprint.Bytes(),
		Size:        res.Size,

		Username:  res.Username,
		Timestamp: res.Timestamp,

		StoragePath: stored.storagePath,
	}

	return stored, doc
}
開發者ID:bac,項目名稱:juju,代碼行數:33,代碼來源:resources_persistence_test.go

示例3: newResource

func newResource(c *gc.C, name, username, data string) (resource.Resource, api.Resource) {
	opened := resourcetesting.NewResource(c, nil, name, "a-service", data)
	res := opened.Resource
	res.Username = username
	if username == "" {
		res.Timestamp = time.Time{}
	}

	apiRes := api.Resource{
		CharmResource: api.CharmResource{
			Name:        name,
			Type:        "file",
			Path:        res.Path,
			Origin:      "upload",
			Revision:    0,
			Fingerprint: res.Fingerprint.Bytes(),
			Size:        res.Size,
		},
		ID:        res.ID,
		ServiceID: res.ServiceID,
		Username:  username,
		Timestamp: res.Timestamp,
	}

	return res, apiRes
}
開發者ID:makyo,項目名稱:juju,代碼行數:26,代碼來源:base_test.go

示例4: TestServeHTTPDownloadOkay

func (s *LegacyHTTPHandlerSuite) TestServeHTTPDownloadOkay(c *gc.C) {
	s.deps.ReturnNewResourceOpener = s.opener
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
	s.deps.ReturnHandleDownload = opened
	h := &server.LegacyHTTPHandler{
		LegacyHTTPHandlerDeps: s.deps,
	}
	req, err := http.NewRequest("GET", "...", nil)
	c.Assert(err, jc.ErrorIsNil)

	h.ServeHTTP(s.resp, req)

	s.stub.CheckCallNames(c,
		"NewResourceOpener",
		"HandleDownload",
		"UpdateDownloadResponse",
		"WriteHeader",
		"Copy",
		"Close",
	)
	s.stub.CheckCall(c, 0, "NewResourceOpener", req)
	s.stub.CheckCall(c, 1, "HandleDownload", s.opener, req)
	s.stub.CheckCall(c, 2, "UpdateDownloadResponse", s.resp, opened.Resource)
	s.stub.CheckCall(c, 3, "WriteHeader", http.StatusOK)
	s.stub.CheckCall(c, 4, "Copy", s.resp, opened)
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:26,代碼來源:handler_test.go

示例5: newCharmResource

func newCharmResource(c *gc.C, name, data string, rev int) charmresource.Resource {
	opened := resourcetesting.NewResource(c, nil, name, "a-application", data)
	chRes := opened.Resource.Resource
	chRes.Origin = charmresource.OriginStore
	chRes.Revision = rev
	return chRes
}
開發者ID:bac,項目名稱:juju,代碼行數:7,代碼來源:resource_test.go

示例6: newResource

func newResource(c *gc.C, name, username, data string) (resource.Resource, api.Resource) {
	opened := resourcetesting.NewResource(c, nil, name, "a-application", data)
	res := opened.Resource
	res.Revision = 1
	res.Username = username
	if username == "" {
		// Note that resourcetesting.NewResource() returns a resources
		// with a username and timestamp set. So if the username was
		// "un-set" then we have to also unset the timestamp.
		res.Timestamp = time.Time{}
	}

	apiRes := api.Resource{
		CharmResource: api.CharmResource{
			Name:        name,
			Type:        "file",
			Path:        res.Path,
			Origin:      "upload",
			Revision:    1,
			Fingerprint: res.Fingerprint.Bytes(),
			Size:        res.Size,
		},
		ID:            res.ID,
		ApplicationID: res.ApplicationID,
		Username:      username,
		Timestamp:     res.Timestamp,
	}

	return res, apiRes
}
開發者ID:bac,項目名稱:juju,代碼行數:30,代碼來源:base_test.go

示例7: TestWrite

func (s *DirectorySuite) TestWrite(c *gc.C) {
	res := resourcetesting.NewResource(c, s.stub.Stub, "spam", "a-application", "some data")
	stub := &stubDirectory{
		internalStub: s.stub,
	}
	stub.ReturnInfo = res.Resource
	opened := stub
	dataDir := "/var/lib/juju/agents/unit-spam-1/resources"
	deps := s.stub
	spec := internal.NewDirectorySpec(dataDir, "eggs", deps)
	s.stub.ResetCalls()
	dir := internal.NewDirectory(spec, deps)

	err := dir.Write(opened)
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCallNames(c,
		"Info",
		"Content",
		"Join",
		"CreateWriter",
		"WriteContent",
		"CloseAndLog",
	)
}
開發者ID:bac,項目名稱:juju,代碼行數:25,代碼來源:resourcedir_test.go

示例8: newStoreResource

func newStoreResource(c *gc.C, name, data string) resource.Resource {
	opened := resourcetesting.NewResource(c, nil, name, "a-application", data)
	res := opened.Resource
	res.Origin = charmresource.OriginStore
	res.Revision = 1
	res.Username = ""
	res.Timestamp = time.Time{}
	return res
}
開發者ID:bac,項目名稱:juju,代碼行數:9,代碼來源:resource_test.go

示例9: newStoreResource

func newStoreResource(c *gc.C, name, serviceID string, revision int) resource.Resource {
	content := name
	opened := resourcetesting.NewResource(c, nil, name, serviceID, content)
	res := opened.Resource
	res.Origin = charmresource.OriginStore
	res.Revision = revision
	err := res.Validate()
	c.Assert(err, jc.ErrorIsNil)
	return res
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:10,代碼來源:service_test.go

示例10: newResource

func newResource(c *gc.C, stub *testing.Stub, name, content string) (resource.Resource, io.ReadCloser) {
	opened := resourcetesting.NewResource(c, stub, name, "a-application", content)
	res := opened.Resource
	if content != "" {
		return res, opened.ReadCloser
	}
	res.Username = ""
	res.Timestamp = time.Time{}
	return res, nil
}
開發者ID:bac,項目名稱:juju,代碼行數:10,代碼來源:base_test.go

示例11: TestGetResource

func (s *UnitFacadeClientSuite) TestGetResource(c *gc.C) {
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-application", "some data")
	s.api.setResource(opened.Resource, opened)
	cl := client.NewUnitFacadeClient(s.api, s.api)

	info, content, err := cl.GetResource("spam")
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "Do", "FacadeCall")
	c.Check(info, jc.DeepEquals, opened.Resource)
	c.Check(content, jc.DeepEquals, opened)
}
開發者ID:bac,項目名稱:juju,代碼行數:12,代碼來源:client_test.go

示例12: step

func (s pushResource) step(c *gc.C, ctx *context) {
	opened := resourcetesting.NewResource(c, &gt.Stub{}, "data", ctx.unit.ApplicationName(), "the bytes")

	res, err := ctx.st.Resources()
	c.Assert(err, jc.ErrorIsNil)
	_, err = res.SetResource(
		ctx.unit.ApplicationName(),
		opened.Username,
		opened.Resource.Resource,
		opened.ReadCloser,
	)
	c.Assert(err, jc.ErrorIsNil)
}
開發者ID:bac,項目名稱:juju,代碼行數:13,代碼來源:util_test.go

示例13: TestOpenResourceSizeMismatch

func (s *ResourceSuite) TestOpenResourceSizeMismatch(c *gc.C) {
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-application", "some data")
	s.persist.ReturnGetResource = opened.Resource
	s.persist.ReturnGetResourcePath = "application-a-application/resources/spam"
	content := opened.Content()
	content.Size += 1
	s.storage.ReturnGet = content
	st := NewState(s.raw)
	s.stub.ResetCalls()

	_, _, err := st.OpenResource("a-application", "spam")

	s.stub.CheckCallNames(c, "GetResource", "Get")
	c.Check(err, gc.ErrorMatches, `storage returned a size \(10\) which doesn't match resource metadata \(9\)`)
}
開發者ID:bac,項目名稱:juju,代碼行數:15,代碼來源:resource_test.go

示例14: TestOpenResourceOkay

func (s *ResourceSuite) TestOpenResourceOkay(c *gc.C) {
	data := "some data"
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-application", data)
	s.persist.ReturnGetResource = opened.Resource
	s.persist.ReturnGetResourcePath = "application-a-application/resources/spam"
	s.storage.ReturnGet = opened.Content()
	st := NewState(s.raw)
	s.stub.ResetCalls()

	info, reader, err := st.OpenResource("a-application", "spam")
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c, "GetResource", "Get")
	s.stub.CheckCall(c, 1, "Get", "application-a-application/resources/spam")
	c.Check(info, jc.DeepEquals, opened.Resource)
	c.Check(reader, gc.Equals, opened.ReadCloser)
}
開發者ID:bac,項目名稱:juju,代碼行數:17,代碼來源:resource_test.go

示例15: TestHandleDownload

func (s *DownloadSuite) TestHandleDownload(c *gc.C) {
	opened := resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
	s.deps.ReturnExtractDownloadRequest = "spam"
	s.store.ReturnOpenResource = opened
	req, err := http.NewRequest("GET", "...", nil)
	c.Assert(err, jc.ErrorIsNil)

	res, reader, err := server.HandleDownload(req, s.deps)
	c.Assert(err, jc.ErrorIsNil)

	s.stub.CheckCallNames(c,
		"ExtractDownloadRequest",
		"OpenResource",
	)
	c.Check(res, jc.DeepEquals, opened.Resource)
	c.Check(reader, gc.Equals, opened.ReadCloser)
}
開發者ID:OSBI,項目名稱:juju,代碼行數:17,代碼來源:download_test.go


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