本文整理汇总了Golang中github.com/juju/juju/api/block.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getBlockAPI
// getBlockAPI returns a block api for listing blocks.
func getBlockAPI(c *envcmd.EnvCommandBase) (block.BlockListAPI, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, err
}
return apiblock.NewClient(root), nil
}
示例2: getBlockAPI
// getBlockAPI returns a block api for block manipulation.
func getBlockAPI(c newAPIRoot) (*apiblock.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, err
}
return apiblock.NewClient(root), nil
}
示例3: TestSwitchBlockOff
func (s *blockMockSuite) TestSwitchBlockOff(c *gc.C) {
called := false
blockType := state.DestroyBlock.String()
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, response interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Block")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "SwitchBlockOff")
args, ok := a.(params.BlockSwitchParams)
c.Assert(ok, jc.IsTrue)
// message is never sent, so this argument should
// always be empty string.
c.Assert(args.Message, gc.DeepEquals, "")
c.Assert(args.Type, gc.DeepEquals, blockType)
_, ok = response.(*params.ErrorResult)
c.Assert(ok, jc.IsTrue)
return nil
})
blockClient := block.NewClient(apiCaller)
err := blockClient.SwitchBlockOff(blockType)
c.Assert(called, jc.IsTrue)
c.Assert(err, gc.IsNil)
}
示例4: getBlockAPI
// getBlockAPI returns a block api for listing blocks.
func getBlockAPI(c *modelcmd.ModelCommandBase) (listBlocksAPI, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return block.NewClient(root), nil
}
示例5: TestSwitchBlockOn
func (s *blockMockSuite) TestSwitchBlockOn(c *gc.C) {
called := false
blockType := state.DestroyBlock.String()
msg := "for test switch block on"
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, response interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Block")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "SwitchBlockOn")
args, ok := a.(params.BlockSwitchParams)
c.Assert(ok, jc.IsTrue)
c.Assert(args.Message, gc.DeepEquals, msg)
c.Assert(args.Type, gc.DeepEquals, blockType)
_, ok = response.(*params.ErrorResult)
c.Assert(ok, jc.IsTrue)
return nil
})
blockClient := block.NewClient(apiCaller)
err := blockClient.SwitchBlockOn(blockType, msg)
c.Assert(called, jc.IsTrue)
c.Assert(err, gc.IsNil)
}
示例6: SetUpTest
func (s *blockSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.blockClient = block.NewClient(s.APIState)
c.Assert(s.blockClient, gc.NotNil)
s.AddCleanup(func(*gc.C) {
s.blockClient.ClientFacade.Close()
})
}
示例7: SetUpTest
func (s *blockSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
c.Assert(err, jc.ErrorIsNil)
s.AddCleanup(func(*gc.C) { conn.Close() })
s.ctx = &mockContext{
agentConfig: &mockAgentConfig{dataDir: s.DataDir()},
apiState: conn,
state: s.State,
}
s.blockClient = block.NewClient(conn)
}
示例8: TestSwitchBlockOnError
func (s *blockMockSuite) TestSwitchBlockOnError(c *gc.C) {
called := false
errmsg := "test error"
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, response interface{},
) error {
called = true
result, ok := response.(*params.ErrorResult)
c.Assert(ok, jc.IsTrue)
result.Error = common.ServerError(errors.New(errmsg))
return nil
})
blockClient := block.NewClient(apiCaller)
err := blockClient.SwitchBlockOn("", "")
c.Assert(called, jc.IsTrue)
c.Assert(errors.Cause(err), gc.ErrorMatches, errmsg)
}
示例9: TestList
func (s *blockMockSuite) TestList(c *gc.C) {
var called bool
one := params.BlockResult{
Result: params.Block{
Id: "-42",
Type: state.DestroyBlock.String(),
Message: "for test switch on",
Tag: "some valid tag, right?",
},
}
errmsg := "another test error"
two := params.BlockResult{
Error: common.ServerError(errors.New(errmsg)),
}
apiCaller := basetesting.APICallerFunc(
func(
objType string,
version int,
id, request string,
a, response interface{}) error {
called = true
c.Check(objType, gc.Equals, "Block")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "List")
c.Assert(a, gc.IsNil)
result := response.(*params.BlockResults)
result.Results = []params.BlockResult{one, two}
return nil
})
blockClient := block.NewClient(apiCaller)
found, err := blockClient.List()
c.Assert(called, jc.IsTrue)
c.Assert(errors.Cause(err), gc.ErrorMatches, errmsg)
c.Assert(found, gc.HasLen, 1)
}
示例10: NewBlockHelper
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st api.Connection) BlockHelper {
return BlockHelper{
blockClient: block.NewClient(st),
}
}
示例11: NewBlockHelper
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st *api.State) BlockHelper {
return BlockHelper{
blockClient: block.NewClient(st),
}
}
示例12: NewBlockHelper
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st api.Connection) BlockHelper {
return BlockHelper{
ApiState: st,
client: block.NewClient(st),
}
}
示例13: SetUpTest
func (s *blockSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
s.blockClient = block.NewClient(s.APIState)
c.Assert(s.blockClient, gc.NotNil)
}
示例14: NewBlockHelper
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st *api.State) BlockHelper {
return BlockHelper{
ApiState: st,
client: block.NewClient(st),
}
}
示例15: NewCmdBlockHelper
// NewCmdBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewCmdBlockHelper(api base.APICallCloser) CmdBlockHelper {
return CmdBlockHelper{
blockClient: block.NewClient(api),
}
}