本文整理汇总了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),
}},
})
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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",
)
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例12: step
func (s pushResource) step(c *gc.C, ctx *context) {
opened := resourcetesting.NewResource(c, >.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)
}
示例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\)`)
}
示例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)
}
示例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)
}