本文整理汇总了Golang中github.com/juju/juju/api/instancepoller.NewAPI函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAPI函数的具体用法?Golang NewAPI怎么用?Golang NewAPI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAPI函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWatchEnvironMachinesSuccess
func (s *InstancePollerSuite) TestWatchEnvironMachinesSuccess(c *gc.C) {
// We're not testing the watcher logic here as it's already tested elsewhere.
var numFacadeCalls int
var numWatcherCalls int
expectResult := params.StringsWatchResult{
StringsWatcherId: "42",
Changes: []string{"foo", "bar"},
}
watcherFunc := func(caller base.APICaller, result params.StringsWatchResult) watcher.StringsWatcher {
numWatcherCalls++
c.Check(caller, gc.NotNil)
c.Check(result, jc.DeepEquals, expectResult)
return nil
}
s.PatchValue(instancepoller.NewStringsWatcher, watcherFunc)
apiCaller := successAPICaller(c, "WatchEnvironMachines", nil, expectResult, &numFacadeCalls)
api := instancepoller.NewAPI(apiCaller)
w, err := api.WatchEnvironMachines()
c.Assert(err, jc.ErrorIsNil)
c.Assert(numFacadeCalls, gc.Equals, 1)
c.Assert(numWatcherCalls, gc.Equals, 1)
c.Assert(w, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:instancepoller_test.go
示例2: start
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
var clock clock.Clock
if err := context.Get(config.ClockName, &clock); err != nil {
return nil, errors.Trace(err)
}
var environ environs.Environ
if err := context.Get(config.EnvironName, &environ); err != nil {
return nil, errors.Trace(err)
}
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, errors.Trace(err)
}
facade := instancepoller.NewAPI(apiCaller)
w, err := NewWorker(Config{
Clock: clock,
Delay: config.Delay,
Facade: facade,
Environ: environ,
})
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:manifold.go
示例3: manifoldStart
// manifoldStart creates an instancepoller worker, given a base.APICaller.
func manifoldStart(apiCaller base.APICaller) (worker.Worker, error) {
api := instancepoller.NewAPI(apiCaller)
w, err := NewWorker(api)
if err != nil {
return nil, errors.Trace(err)
}
return w, nil
}
开发者ID:exekias,项目名称:juju,代码行数:9,代码来源:manifold.go
示例4: TestWatchEnvironMachinesClientError
func (s *InstancePollerSuite) TestWatchEnvironMachinesClientError(c *gc.C) {
var called int
apiCaller := clientErrorAPICaller(c, "WatchEnvironMachines", nil, &called)
api := instancepoller.NewAPI(apiCaller)
w, err := api.WatchEnvironMachines()
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(w, gc.IsNil)
c.Assert(called, gc.Equals, 1)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:instancepoller_test.go
示例5: TestEnvironConfigClientError
func (s *InstancePollerSuite) TestEnvironConfigClientError(c *gc.C) {
var called int
apiCaller := clientErrorAPICaller(c, "EnvironConfig", nil, &called)
api := instancepoller.NewAPI(apiCaller)
cfg, err := api.EnvironConfig()
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(cfg, gc.IsNil)
c.Assert(called, gc.Equals, 1)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:instancepoller_test.go
示例6: TestWatchForEnvironConfigChangesClientError
func (s *InstancePollerSuite) TestWatchForEnvironConfigChangesClientError(c *gc.C) {
// We're not testing the success case as we're not patching the
// NewNotifyWatcher call the embedded EnvironWatcher is calling.
var called int
apiCaller := clientErrorAPICaller(c, "WatchForEnvironConfigChanges", nil, &called)
api := instancepoller.NewAPI(apiCaller)
w, err := api.WatchForEnvironConfigChanges()
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(called, gc.Equals, 1)
c.Assert(w, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:instancepoller_test.go
示例7: TestWatchEnvironMachinesServerError
func (s *InstancePollerSuite) TestWatchEnvironMachinesServerError(c *gc.C) {
var called int
expectedResults := params.StringsWatchResult{
Error: apiservertesting.ServerError("server boom!"),
}
apiCaller := successAPICaller(c, "WatchEnvironMachines", nil, expectedResults, &called)
api := instancepoller.NewAPI(apiCaller)
w, err := api.WatchEnvironMachines()
c.Assert(err, gc.ErrorMatches, "server boom!")
c.Assert(called, gc.Equals, 1)
c.Assert(w, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:instancepoller_test.go
示例8: TestNewAPI
func (s *InstancePollerSuite) TestNewAPI(c *gc.C) {
var called int
apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
api := instancepoller.NewAPI(apiCaller)
c.Check(api, gc.NotNil)
c.Check(called, gc.Equals, 0)
// Nothing happens until we actually call something else.
m, err := api.Machine(names.MachineTag{})
c.Assert(err, gc.ErrorMatches, "client error!")
c.Assert(m, gc.IsNil)
c.Assert(called, gc.Equals, 1)
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:instancepoller_test.go
示例9: TestEnvironConfigServerError
func (s *InstancePollerSuite) TestEnvironConfigServerError(c *gc.C) {
var called int
expectResults := params.EnvironConfigResult{
Config: params.EnvironConfig{"type": "foo"},
}
apiCaller := successAPICaller(c, "EnvironConfig", nil, expectResults, &called)
api := instancepoller.NewAPI(apiCaller)
cfg, err := api.EnvironConfig()
c.Assert(err, gc.NotNil) // the actual error doesn't matter
c.Assert(called, gc.Equals, 1)
c.Assert(cfg, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:13,代码来源:instancepoller_test.go
示例10: TestEnvironConfigSuccess
func (s *InstancePollerSuite) TestEnvironConfigSuccess(c *gc.C) {
var called int
expectedConfig := coretesting.EnvironConfig(c)
expectedResults := params.EnvironConfigResult{
Config: params.EnvironConfig(expectedConfig.AllAttrs()),
}
apiCaller := successAPICaller(c, "EnvironConfig", nil, expectedResults, &called)
api := instancepoller.NewAPI(apiCaller)
cfg, err := api.EnvironConfig()
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, gc.Equals, 1)
c.Assert(cfg, jc.DeepEquals, expectedConfig)
}
开发者ID:imoapps,项目名称:juju,代码行数:14,代码来源:instancepoller_test.go
示例11: TestMachineCallsLife
func (s *InstancePollerSuite) TestMachineCallsLife(c *gc.C) {
// We have tested separately the Life method, here we just check
// it's called internally.
var called int
expectedResults := params.LifeResults{
Results: []params.LifeResult{{Life: "working"}},
}
apiCaller := successAPICaller(c, "Life", entitiesArgs, expectedResults, &called)
api := instancepoller.NewAPI(apiCaller)
m, err := api.Machine(names.NewMachineTag("42"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, gc.Equals, 1)
c.Assert(m.Life(), gc.Equals, params.Life("working"))
c.Assert(m.Id(), gc.Equals, "42")
}
开发者ID:imoapps,项目名称:juju,代码行数:15,代码来源:instancepoller_test.go
示例12: InstancePoller
// InstancePoller returns access to the InstancePoller API
func (st *State) InstancePoller() *instancepoller.API {
return instancepoller.NewAPI(st)
}
开发者ID:Pankov404,项目名称:juju,代码行数:4,代码来源:state.go
示例13: TestNewAPIWithNilCaller
func (s *InstancePollerSuite) TestNewAPIWithNilCaller(c *gc.C) {
panicFunc := func() { instancepoller.NewAPI(nil) }
c.Assert(panicFunc, gc.PanicMatches, "caller is nil")
}
开发者ID:imoapps,项目名称:juju,代码行数:4,代码来源:instancepoller_test.go
注:本文中的github.com/juju/juju/api/instancepoller.NewAPI函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论