本文整理汇总了Golang中github.com/juju/juju/resource/resourcetesting.NewResource函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResource函数的具体用法?Golang NewResource怎么用?Golang NewResource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResource函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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, >.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
示例16: TestGetResourceInfoEmpty
func (s *UnitFacadeSuite) TestGetResourceInfoEmpty(c *gc.C) {
opened := resourcetesting.NewResource(c, s.stub, "spam", "a-application", "some data")
store := &stubUnitDataStore{Stub: s.stub}
store.ReturnListResources = resource.ServiceResources{
Resources: []resource.Resource{opened.Resource},
}
uf := server.UnitFacade{DataStore: store}
results, err := uf.GetResourceInfo(private.ListResourcesArgs{
ResourceNames: []string{},
})
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "ListResources")
c.Check(results, jc.DeepEquals, private.ResourcesResult{
Resources: []private.ResourceResult{},
})
}
开发者ID:bac,项目名称:juju,代码行数:18,代码来源:unitfacade_test.go
示例17: TestIntegration
func (s *LegacyHTTPHandlerSuite) TestIntegration(c *gc.C) {
opened := resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
s.store.ReturnOpenResource = opened
s.deps.ReturnConnect = s.store
h := server.NewLegacyHTTPHandler(s.deps.Connect)
req, err := api.NewHTTPDownloadRequest("spam")
c.Assert(err, jc.ErrorIsNil)
req.URL, err = url.ParseRequestURI("https://api:17017/units/eggs/1/resources/spam?:resource=spam")
c.Assert(err, jc.ErrorIsNil)
resp := &fakeResponseWriter{
stubResponseWriter: s.resp,
}
h.ServeHTTP(resp, req)
resp.checkWritten(c, "some data", http.Header{
"Content-Type": []string{api.ContentTypeRaw},
"Content-Length": []string{"9"}, // len("some data")
"Content-Sha384": []string{opened.Fingerprint.String()},
})
}
开发者ID:OSBI,项目名称:juju,代码行数:21,代码来源:handler_test.go
示例18: TestServeHTTPDownloadCopyFailed
func (s *LegacyHTTPHandlerSuite) TestServeHTTPDownloadCopyFailed(c *gc.C) {
s.deps.ReturnHandleDownload = resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
h := &server.LegacyHTTPHandler{
LegacyHTTPHandlerDeps: s.deps,
}
failure := errors.New("<failure>")
s.stub.SetErrors(nil, nil, failure)
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",
)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:21,代码来源:handler_test.go
示例19: TestOpenResourceForUniterOkay
func (s *ResourceSuite) TestOpenResourceForUniterOkay(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()
unit := newUnit(s.stub, "a-application/0")
st := NewState(s.raw)
s.stub.ResetCalls()
info, reader, err := st.OpenResourceForUniter(unit, "spam")
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "ApplicationName", "GetResource", "Get", "Name", "SetUnitResourceProgress")
s.stub.CheckCall(c, 2, "Get", "application-a-application/resources/spam")
c.Check(info, jc.DeepEquals, opened.Resource)
b, err := ioutil.ReadAll(reader)
// note ioutil.ReadAll converts EOF to nil
c.Check(err, jc.ErrorIsNil)
c.Check(b, gc.DeepEquals, []byte(data))
}
开发者ID:bac,项目名称:juju,代码行数:22,代码来源:resource_test.go
示例20: TestGetResourceInfoNotFound
func (s *UnitFacadeSuite) TestGetResourceInfoNotFound(c *gc.C) {
opened := resourcetesting.NewResource(c, s.stub, "spam", "a-service", "some data")
store := &stubUnitDataStore{Stub: s.stub}
store.ReturnListResources = resource.ServiceResources{
Resources: []resource.Resource{opened.Resource},
}
uf := server.UnitFacade{DataStore: store}
results, err := uf.GetResourceInfo(private.ListResourcesArgs{
ResourceNames: []string{"eggs"},
})
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "ListResources")
c.Check(results, jc.DeepEquals, private.ResourcesResult{
Resources: []private.ResourceResult{{
ErrorResult: params.ErrorResult{
Error: common.ServerError(errors.NotFoundf(`resource "eggs"`)),
},
}},
})
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:22,代码来源:unitfacade_test.go
注:本文中的github.com/juju/juju/resource/resourcetesting.NewResource函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论