本文整理汇总了Golang中github.com/juju/juju/resource/api/server.NewFacade函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFacade函数的具体用法?Golang NewFacade怎么用?Golang NewFacade使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFacade函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNoURL
func (s *AddPendingResourcesSuite) TestNoURL(c *gc.C) {
res1, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
id1 := "some-unique-ID"
s.data.ReturnAddPendingResource = id1
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
result, err := facade.AddPendingResources(api.AddPendingResourcesArgs{
Entity: params.Entity{
Tag: "service-a-service",
},
Resources: []api.CharmResource{
apiRes1.CharmResource,
},
})
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "AddPendingResource")
s.stub.CheckCall(c, 0, "AddPendingResource", "a-service", "", res1.Resource, nil)
c.Check(result, jc.DeepEquals, api.AddPendingResourcesResult{
PendingIDs: []string{
id1,
},
})
}
示例2: TestUnknownResource
func (s *AddPendingResourcesSuite) TestUnknownResource(c *gc.C) {
res1, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
res1.Origin = charmresource.OriginStore
res1.Revision = 3
apiRes1.Origin = charmresource.OriginStore.String()
apiRes1.Revision = 3
id1 := "some-unique-ID"
s.data.ReturnAddPendingResource = id1
s.csClient.ReturnListResources = [][]charmresource.Resource{{
res1.Resource,
}}
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
result, err := facade.AddPendingResources(api.AddPendingResourcesArgs{
Entity: params.Entity{
Tag: "service-a-service",
},
AddCharmWithAuthorization: params.AddCharmWithAuthorization{
URL: "cs:~a-user/trusty/spam-5",
},
Resources: []api.CharmResource{
apiRes1.CharmResource,
},
})
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "newCSClient", "ListResources", "AddPendingResource")
s.stub.CheckCall(c, 2, "AddPendingResource", "a-service", "", res1.Resource, nil)
c.Check(result, jc.DeepEquals, api.AddPendingResourcesResult{
PendingIDs: []string{
id1,
},
})
}
示例3: TestLocalCharm
func (s *AddPendingResourcesSuite) TestLocalCharm(c *gc.C) {
res1, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
expected := charmresource.Resource{
Meta: res1.Meta,
Origin: charmresource.OriginUpload,
}
apiRes1.Origin = charmresource.OriginStore.String()
apiRes1.Revision = 3
id1 := "some-unique-ID"
s.data.ReturnAddPendingResource = id1
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
result, err := facade.AddPendingResources(api.AddPendingResourcesArgs{
Entity: params.Entity{
Tag: "service-a-service",
},
AddCharmWithAuthorization: params.AddCharmWithAuthorization{
URL: "local:trusty/spam",
},
Resources: []api.CharmResource{
apiRes1.CharmResource,
},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Error, gc.IsNil)
s.stub.CheckCallNames(c, "AddPendingResource")
s.stub.CheckCall(c, 0, "AddPendingResource", "a-service", "", expected, nil)
c.Check(result, jc.DeepEquals, api.AddPendingResourcesResult{
PendingIDs: []string{
id1,
},
})
}
示例4: newPublicFacade
// newPublicFacade is passed into common.RegisterStandardFacade
// in registerPublicFacade.
func (resources) newPublicFacade(st *corestate.State, _ *common.Resources, authorizer common.Authorizer) (*server.Facade, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
rst, err := st.Resources()
//rst, err := state.NewState(&resourceState{raw: st})
if err != nil {
return nil, errors.Trace(err)
}
return server.NewFacade(rst), nil
}
示例5: TestEmpty
func (s *ListResourcesSuite) TestEmpty(c *gc.C) {
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
results, err := facade.ListResources(api.ListResourcesArgs{
Entities: []params.Entity{{
Tag: "application-a-application",
}},
})
c.Assert(err, jc.ErrorIsNil)
c.Check(results, jc.DeepEquals, api.ResourcesResults{
Results: []api.ResourcesResult{{}},
})
s.stub.CheckCallNames(c, "ListResources")
}
示例6: TestWithURLMismatchIncomplete
func (s *AddPendingResourcesSuite) TestWithURLMismatchIncomplete(c *gc.C) {
res1, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
res1.Origin = charmresource.OriginStore
res1.Revision = 2
apiRes1.Origin = charmresource.OriginStore.String()
apiRes1.Revision = 3
apiRes1.Fingerprint = nil
apiRes1.Size = 0
id1 := "some-unique-ID"
s.data.ReturnAddPendingResource = id1
csRes := res1 // a copy
csRes.Revision = 2
s.csClient.ReturnListResources = [][]charmresource.Resource{{
csRes.Resource,
}}
expected := charmresource.Resource{
Meta: csRes.Meta,
Origin: charmresource.OriginStore,
Revision: 3,
Fingerprint: res1.Fingerprint,
Size: res1.Size,
}
s.csClient.ReturnResourceInfo = &expected
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
result, err := facade.AddPendingResources(api.AddPendingResourcesArgs{
Entity: params.Entity{
Tag: "service-a-service",
},
AddCharmWithAuthorization: params.AddCharmWithAuthorization{
URL: "cs:~a-user/trusty/spam-5",
},
Resources: []api.CharmResource{
apiRes1.CharmResource,
},
})
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "newCSClient", "ListResources", "ResourceInfo", "AddPendingResource")
s.stub.CheckCall(c, 3, "AddPendingResource", "a-service", "", expected, nil)
c.Check(result, jc.DeepEquals, api.AddPendingResourcesResult{
PendingIDs: []string{
id1,
},
})
}
示例7: NewPublicFacade
// NewPublicFacade provides the public API facade for resources. It is
// passed into common.RegisterStandardFacade.
func NewPublicFacade(st *corestate.State, _ *common.Resources, authorizer common.Authorizer) (*server.Facade, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
rst, err := st.Resources()
if err != nil {
return nil, errors.Trace(err)
}
newClient := func() (server.CharmStore, error) {
return newCharmStoreClient(st)
}
facade, err := server.NewFacade(rst, newClient)
if err != nil {
return nil, errors.Trace(err)
}
return facade, nil
}
示例8: NewPublicFacade
// NewPublicFacade provides the public API facade for resources. It is
// passed into common.RegisterStandardFacade.
func NewPublicFacade(st *corestate.State, _ *common.Resources, authorizer common.Authorizer) (*server.Facade, error) {
if !authorizer.AuthClient() {
return nil, common.ErrPerm
}
rst, err := st.Resources()
if err != nil {
return nil, errors.Trace(err)
}
newClient := func(cURL *charm.URL, csMac *macaroon.Macaroon) (server.CharmStore, error) {
opener := newCharmstoreOpener(cURL, csMac)
return opener.newClient(), nil
}
facade, err := server.NewFacade(rst, newClient)
if err != nil {
return nil, errors.Trace(err)
}
return facade, nil
}
示例9: TestWithURLNoRevision
func (s *AddPendingResourcesSuite) TestWithURLNoRevision(c *gc.C) {
res1, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
res1.Origin = charmresource.OriginStore
res1.Revision = 3
res1.Size = 10
apiRes1.Origin = charmresource.OriginStore.String()
apiRes1.Revision = -1
apiRes1.Size = 0
apiRes1.Fingerprint = nil
id1 := "some-unique-ID"
s.data.ReturnAddPendingResource = id1
csRes := res1 // a copy
csRes.Revision = 3
csRes.Size = 10
s.csClient.ReturnListResources = [][]charmresource.Resource{{
csRes.Resource,
}}
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
result, err := facade.AddPendingResources(api.AddPendingResourcesArgs{
Entity: params.Entity{
Tag: "application-a-application",
},
AddCharmWithAuthorization: params.AddCharmWithAuthorization{
URL: "cs:~a-user/trusty/spam-5",
},
Resources: []api.CharmResource{
apiRes1.CharmResource,
},
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.Error, gc.IsNil)
s.stub.CheckCallNames(c, "newCSClient", "ListResources", "AddPendingResource")
s.stub.CheckCall(c, 2, "AddPendingResource", "a-application", "", res1.Resource, nil)
c.Check(result, jc.DeepEquals, api.AddPendingResourcesResult{
PendingIDs: []string{
id1,
},
})
}
示例10: TestError
func (s *ListResourcesSuite) TestError(c *gc.C) {
failure := errors.New("<failure>")
s.stub.SetErrors(failure)
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
results, err := facade.ListResources(api.ListResourcesArgs{
Entities: []params.Entity{{
Tag: "application-a-application",
}},
})
c.Assert(err, jc.ErrorIsNil)
c.Check(results, jc.DeepEquals, api.ResourcesResults{
Results: []api.ResourcesResult{{
ErrorResult: params.ErrorResult{Error: ¶ms.Error{
Message: "<failure>",
}},
}},
})
s.stub.CheckCallNames(c, "ListResources")
}
示例11: TestDataStoreError
func (s *AddPendingResourcesSuite) TestDataStoreError(c *gc.C) {
_, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
failure := errors.New("<failure>")
s.stub.SetErrors(failure)
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
result, err := facade.AddPendingResources(api.AddPendingResourcesArgs{
Entity: params.Entity{
Tag: "service-a-service",
},
Resources: []api.CharmResource{
apiRes1.CharmResource,
},
})
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "AddPendingResource")
c.Check(result, jc.DeepEquals, api.AddPendingResourcesResult{
ErrorResult: params.ErrorResult{Error: ¶ms.Error{
Message: `while adding pending resource info for "spam": <failure>`,
}},
})
}
示例12: TestNewFacadeMissingCSClientFactory
func (s *FacadeSuite) TestNewFacadeMissingCSClientFactory(c *gc.C) {
_, err := server.NewFacade(s.data, nil)
c.Check(err, gc.ErrorMatches, `missing factory for new charm store clients`)
}
示例13: TestNewFacadeMissingDataStore
func (s *FacadeSuite) TestNewFacadeMissingDataStore(c *gc.C) {
_, err := server.NewFacade(nil, s.newCSClient)
c.Check(err, gc.ErrorMatches, `missing data store`)
}
示例14: TestNewFacadeOkay
func (s *FacadeSuite) TestNewFacadeOkay(c *gc.C) {
_, err := server.NewFacade(s.data, s.newCSClient)
c.Check(err, jc.ErrorIsNil)
}
示例15: TestOkay
func (s *ListResourcesSuite) TestOkay(c *gc.C) {
res1, apiRes1 := newResource(c, "spam", "a-user", "spamspamspam")
res2, apiRes2 := newResource(c, "eggs", "a-user", "...")
tag0 := names.NewUnitTag("a-application/0")
tag1 := names.NewUnitTag("a-application/1")
chres1 := res1.Resource
chres2 := res2.Resource
chres1.Revision++
chres2.Revision++
apiChRes1 := apiRes1.CharmResource
apiChRes2 := apiRes2.CharmResource
apiChRes1.Revision++
apiChRes2.Revision++
s.data.ReturnListResources = resource.ServiceResources{
Resources: []resource.Resource{
res1,
res2,
},
UnitResources: []resource.UnitResources{
{
Tag: tag0,
Resources: []resource.Resource{
res1,
res2,
},
},
{
Tag: tag1,
},
},
CharmStoreResources: []charmresource.Resource{
chres1,
chres2,
},
}
facade, err := server.NewFacade(s.data, s.newCSClient)
c.Assert(err, jc.ErrorIsNil)
results, err := facade.ListResources(api.ListResourcesArgs{
Entities: []params.Entity{{
Tag: "application-a-application",
}},
})
c.Assert(err, jc.ErrorIsNil)
c.Check(results, jc.DeepEquals, api.ResourcesResults{
Results: []api.ResourcesResult{{
Resources: []api.Resource{
apiRes1,
apiRes2,
},
UnitResources: []api.UnitResources{
{
Entity: params.Entity{
Tag: "unit-a-application-0",
},
Resources: []api.Resource{
apiRes1,
apiRes2,
},
},
{
// we should have a listing for every unit, even if they
// have no resources.
Entity: params.Entity{
Tag: "unit-a-application-1",
},
},
},
CharmStoreResources: []api.CharmResource{
apiChRes1,
apiChRes2,
},
}},
})
s.stub.CheckCallNames(c, "ListResources")
s.stub.CheckCall(c, 0, "ListResources", "a-application")
}