本文整理汇总了Golang中github.com/juju/juju/worker/dependency/testing.StubGetResource函数的典型用法代码示例。如果您正苦于以下问题:Golang StubGetResource函数的具体用法?Golang StubGetResource怎么用?Golang StubGetResource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StubGetResource函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAvailability
// TestAvailability tests that the charmdir resource is properly checked.
func (s *ManifoldSuite) TestAvailability(c *gc.C) {
recorder := &dummyRecorder{
charmURL: "cs:wordpress-37",
unitTag: "wp/0",
isDeclaredMetric: true,
}
s.PatchValue(collect.NewRecorder,
func(_ names.UnitTag, _ context.Paths, _ collect.UnitCharmLookup, _ spool.MetricFactory) (spool.MetricRecorder, error) {
return recorder, nil
})
charmdir := &dummyCharmdir{available: false}
s.dummyResources["charmdir-name"] = dt.StubResource{Output: charmdir}
getResource := dt.StubGetResource(s.dummyResources)
collectEntity, err := (*collect.NewCollect)(s.manifoldConfig, getResource)
c.Assert(err, jc.ErrorIsNil)
err = collectEntity.Do(nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(recorder.batches, gc.HasLen, 0)
charmdir = &dummyCharmdir{available: true}
s.dummyResources["charmdir-name"] = dt.StubResource{Output: charmdir}
getResource = dt.StubGetResource(s.dummyResources)
collectEntity, err = (*collect.NewCollect)(s.manifoldConfig, getResource)
c.Assert(err, jc.ErrorIsNil)
err = collectEntity.Do(nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(recorder.closed, jc.IsTrue)
c.Assert(recorder.batches, gc.HasLen, 1)
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:30,代码来源:manifold_test.go
示例2: TestAvailability
// TestAvailability tests that the charmdir resource is properly checked.
func (s *ManifoldSuite) TestAvailability(c *gc.C) {
recorder := &dummyRecorder{
charmURL: "cs:wordpress-37",
unitTag: "wp/0",
isDeclaredMetric: true,
}
s.PatchValue(collect.NewRecorder,
func(_ names.UnitTag, _ context.Paths, _ spool.MetricFactory) (spool.MetricRecorder, error) {
return recorder, nil
})
s.PatchValue(collect.ReadCharm,
func(_ names.UnitTag, _ context.Paths) (*corecharm.URL, map[string]corecharm.Metric, error) {
return corecharm.MustParseURL("cs:wordpress-37"), map[string]corecharm.Metric{"pings": corecharm.Metric{Description: "test metric", Type: corecharm.MetricTypeAbsolute}}, nil
})
charmdir := &dummyCharmdir{aborted: true}
s.dummyResources["charmdir-name"] = dt.StubResource{Output: charmdir}
getResource := dt.StubGetResource(s.dummyResources)
collectEntity, err := collect.NewCollect(s.manifoldConfig, getResource)
c.Assert(err, jc.ErrorIsNil)
err = collectEntity.Do(nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(recorder.batches, gc.HasLen, 0)
charmdir = &dummyCharmdir{aborted: false}
s.dummyResources["charmdir-name"] = dt.StubResource{Output: charmdir}
getResource = dt.StubGetResource(s.dummyResources)
collectEntity, err = collect.NewCollect(s.manifoldConfig, getResource)
c.Assert(err, jc.ErrorIsNil)
err = collectEntity.Do(nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(recorder.closed, jc.IsTrue)
c.Assert(recorder.batches, gc.HasLen, 1)
}
开发者ID:exekias,项目名称:juju,代码行数:34,代码来源:manifold_test.go
示例3: TestNoAgent
func (s *ManifoldSuite) TestNoAgent(c *gc.C) {
getResource := dt.StubGetResource(dt.StubResources{
"agent": dt.StubResource{Error: dependency.ErrMissing},
})
_, err := s.manifold.Start(getResource)
c.Assert(err, gc.Equals, dependency.ErrMissing)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:manifold_test.go
示例4: TestOutput
func (s *ManifoldSuite) TestOutput(c *gc.C) {
stepsLock := gate.NewLock()
checkLock := gate.NewLock()
getResource := dt.StubGetResource(dt.StubResources{
"steps-waiter": dt.StubResource{Output: stepsLock},
"check-waiter": dt.StubResource{Output: checkLock},
})
w, err := s.manifold.Start(getResource)
c.Assert(err, jc.ErrorIsNil)
// Upgrades not completed yet so output is false.
s.assertOutputFalse(c, w)
// Unlock one of the upgrade gates, output should still be false.
stepsLock.Unlock()
s.assertOutputFalse(c, w)
// Unlock the other gate, output should now be true.
checkLock.Unlock()
s.assertOutputTrue(c, w)
// .. and the worker should exit with ErrBounce.
checkStopWithError(c, w, dependency.ErrBounce)
// Restarting the worker should result in the output immediately
// being true.
w2, err := s.manifold.Start(getResource)
c.Assert(err, jc.ErrorIsNil)
s.assertOutputTrue(c, w)
checkStop(c, w2)
}
开发者ID:exekias,项目名称:juju,代码行数:31,代码来源:manifold_test.go
示例5: SetUpSuite
func (s *ManifoldSuite) SetUpSuite(c *gc.C) {
s.IsolationSuite.SetUpSuite(c)
s.stubAgentApiManifoldConfig = util.AgentApiManifoldConfig{
AgentName: "wut",
APICallerName: "exactly",
}
s.fakeAgent = &fakeAgent{tag: fakeTag}
s.fakeCaller = &fakeCaller{}
s.getResource = dt.StubGetResource(dt.StubResources{
"wut": dt.StubResource{Output: s.fakeAgent},
"exactly": dt.StubResource{Output: s.fakeCaller},
})
s.newFacade = func(facade machineactions.Facade) func(base.APICaller) machineactions.Facade {
s.fakeFacade = facade
return func(apiCaller base.APICaller) machineactions.Facade {
c.Assert(apiCaller, gc.Equals, s.fakeCaller)
return facade
}
}
s.newWorker = func(w worker.Worker, err error) func(machineactions.WorkerConfig) (worker.Worker, error) {
s.fakeWorker = w
return func(wc machineactions.WorkerConfig) (worker.Worker, error) {
c.Assert(wc.Facade, gc.Equals, s.fakeFacade)
c.Assert(wc.MachineTag, gc.Equals, fakeTag)
c.Assert(wc.HandleAction, gc.Equals, fakeHandleAction)
return w, err
}
}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:29,代码来源:manifold_test.go
示例6: TestStartOpenStateNil
func (s *ManifoldSuite) TestStartOpenStateNil(c *gc.C) {
s.config.OpenState = nil
manifold := workerstate.Manifold(s.config)
w, err := manifold.Start(dt.StubGetResource(s.resources))
c.Check(w, gc.IsNil)
c.Check(err, gc.ErrorMatches, "OpenState is nil in config")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:manifold_test.go
示例7: SetUpTest
func (s *ManifoldSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.Stub = testing.Stub{}
s.manifold = apicaller.Manifold(apicaller.ManifoldConfig{
AgentName: "agent-name",
})
s.agent = &mockAgent{
stub: &s.Stub,
env: coretesting.EnvironmentTag,
}
s.getResource = dt.StubGetResource(dt.StubResources{
"agent-name": dt.StubResource{Output: s.agent},
})
// Watch out for this: it uses its own Stub because Close calls are made from
// the worker's loop goroutine. You should make sure to stop the worker before
// checking the mock conn's calls (unless you know the connection will outlive
// the test -- see setupMutatorTest).
s.conn = &mockConn{
stub: &testing.Stub{},
broken: make(chan struct{}),
}
s.PatchValue(apicaller.OpenConnection, func(a agent.Agent) (api.Connection, error) {
s.AddCall("openConnection", a)
if err := s.NextErr(); err != nil {
return nil, err
}
return s.conn, nil
})
}
开发者ID:felicianotech,项目名称:juju,代码行数:31,代码来源:manifold_test.go
示例8: SetUpTest
func (s *ManifoldSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.stub = &testing.Stub{}
s.manifoldConfig = meterstatus.ManifoldConfig{
AgentName: "agent-name",
APICallerName: "apicaller-name",
MachineLockName: "machine-lock-name",
NewHookRunner: meterstatus.NewHookRunner,
NewMeterStatusAPIClient: msapi.NewClient,
NewConnectedStatusWorker: meterstatus.NewConnectedStatusWorker,
NewIsolatedStatusWorker: meterstatus.NewIsolatedStatusWorker,
}
s.manifold = meterstatus.Manifold(s.manifoldConfig)
s.dataDir = c.MkDir()
locksDir := c.MkDir()
lock, err := fslock.NewLock(locksDir, "machine-lock", fslock.Defaults())
c.Assert(err, jc.ErrorIsNil)
s.dummyResources = dt.StubResources{
"agent-name": dt.StubResource{Output: &dummyAgent{dataDir: s.dataDir}},
"apicaller-name": dt.StubResource{Output: &dummyAPICaller{}},
"machine-lock-name": dt.StubResource{Output: lock},
}
s.getResource = dt.StubGetResource(s.dummyResources)
}
开发者ID:imoapps,项目名称:juju,代码行数:28,代码来源:manifold_test.go
示例9: TestStatusWorkerDoesNotRerunAfterRestart
func (s *PatchedManifoldSuite) TestStatusWorkerDoesNotRerunAfterRestart(c *gc.C) {
getResource := dt.StubGetResource(s.dummyResources)
worker, err := s.manifold.Start(getResource)
c.Assert(err, jc.ErrorIsNil)
c.Assert(worker, gc.NotNil)
s.msClient.changes <- struct{}{}
// Kill worker.
worker.Kill()
err = worker.Wait()
c.Assert(err, jc.ErrorIsNil)
// Restart it.
worker, err = s.manifold.Start(getResource)
c.Assert(err, jc.ErrorIsNil)
c.Assert(worker, gc.NotNil)
running := make(chan struct{})
meterstatus.PatchInit(worker, func() { close(running) })
select {
case <-running:
case <-time.After(coretesting.LongWait):
c.Fatal("timed out waiting for signal")
}
worker.Kill()
err = worker.Wait()
s.stub.CheckCallNames(c, "MeterStatus", "RunHook", "WatchMeterStatus", "MeterStatus", "MeterStatus", "WatchMeterStatus")
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:snailwalker,项目名称:juju,代码行数:33,代码来源:manifold_test.go
示例10: startManifold
func (s *ManifoldSuite) startManifold(c *gc.C) (worker.Worker, error) {
w, err := s.manifold.Start(dt.StubGetResource(s.resources))
if w != nil {
s.AddCleanup(func(*gc.C) { worker.Stop(w) })
}
return w, err
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:manifold_test.go
示例11: TestStartNewWorkerError
func (s *ManifoldSuite) TestStartNewWorkerError(c *gc.C) {
expectFacade := &fakeFacade{}
manifold := singular.Manifold(singular.ManifoldConfig{
ClockName: "clock",
APICallerName: "api-caller",
AgentName: "agent",
Duration: time.Minute,
NewFacade: func(_ base.APICaller, _ names.MachineTag) (singular.Facade, error) {
return expectFacade, nil
},
NewWorker: func(config singular.FlagConfig) (worker.Worker, error) {
c.Check(config.Facade, gc.Equals, expectFacade)
err := config.Validate()
c.Check(err, jc.ErrorIsNil)
return nil, errors.New("blomp tik")
},
})
getResource := dt.StubGetResource(dt.StubResources{
"clock": dt.StubResource{Output: &fakeClock{}},
"api-caller": dt.StubResource{Output: &fakeAPICaller{}},
"agent": dt.StubResource{Output: &mockAgent{}},
})
worker, err := manifold.Start(getResource)
c.Check(err, gc.ErrorMatches, "blomp tik")
c.Check(worker, gc.IsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:27,代码来源:manifold_test.go
示例12: TestNoStartStateWorkers
func (s *StateWorkersSuite) TestNoStartStateWorkers(c *gc.C) {
manifold := machine.StateWorkersManifold(machine.StateWorkersConfig{})
worker, err := manifold.Start(dt.StubGetResource(nil))
c.Check(worker, gc.IsNil)
c.Check(err, gc.ErrorMatches, "StartStateWorkers not specified")
c.Check(s.startCalled, jc.IsFalse)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:stateworkers_test.go
示例13: TestStatusWorkerRunsHookOnChanges
func (s *ManifoldSuite) TestStatusWorkerRunsHookOnChanges(c *gc.C) {
msClient := &stubMeterStatusClient{stub: s.stub, changes: make(chan struct{})}
s.PatchValue(meterstatus.NewMeterStatusClient,
func(_ base.APICaller, _ names.UnitTag) msapi.MeterStatusClient {
return msClient
})
s.PatchValue(meterstatus.NewRunner,
func(_ runner.Context, _ context.Paths) runner.Runner {
return &stubRunner{stub: s.stub}
})
getResource := dt.StubGetResource(s.dummyResources)
worker, err := s.manifold.Start(getResource)
c.Assert(err, jc.ErrorIsNil)
c.Assert(worker, gc.NotNil)
running := make(chan struct{})
meterstatus.PatchInit(worker, func() { close(running) })
select {
case <-running:
case <-time.After(coretesting.LongWait):
c.Fatal("timed out waiting for signal")
}
msClient.changes <- struct{}{}
msClient.code = "RED"
worker.Kill()
err = worker.Wait()
c.Assert(err, jc.ErrorIsNil)
s.stub.CheckCallNames(c, "MeterStatus", "RunHook", "WatchMeterStatus", "MeterStatus", "RunHook")
}
开发者ID:kakamessi99,项目名称:juju,代码行数:34,代码来源:manifold_test.go
示例14: TestNewWorkerError
func (s *ManifoldSuite) TestNewWorkerError(c *gc.C) {
fakeClock := &fakeClock{}
fakeFacade := &fakeFacade{}
fakeAPICaller := &fakeAPICaller{}
stub := testing.Stub{}
manifold := charmrevisionmanifold.Manifold(charmrevisionmanifold.ManifoldConfig{
APICallerName: "api-caller",
ClockName: "clock",
NewFacade: func(apiCaller base.APICaller) (charmrevisionmanifold.Facade, error) {
stub.AddCall("NewFacade", apiCaller)
return fakeFacade, nil
},
NewWorker: func(config charmrevision.Config) (worker.Worker, error) {
stub.AddCall("NewWorker", config)
return nil, errors.New("snrght")
},
})
_, err := manifold.Start(dt.StubGetResource(dt.StubResources{
"api-caller": dt.StubResource{Output: fakeAPICaller},
"clock": dt.StubResource{Output: fakeClock},
}))
c.Check(err, gc.ErrorMatches, "cannot create worker: snrght")
stub.CheckCalls(c, []testing.StubCall{{
"NewFacade", []interface{}{fakeAPICaller},
}, {
"NewWorker", []interface{}{charmrevision.Config{
RevisionUpdater: fakeFacade,
Clock: fakeClock,
}},
}})
}
开发者ID:exekias,项目名称:juju,代码行数:33,代码来源:manifold_test.go
示例15: checkNotStateServer
func (s *ServingInfoSetterSuite) checkNotStateServer(c *gc.C, job multiwatcher.MachineJob) {
a := &mockAgent{}
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, args, response interface{}) error {
c.Assert(objType, gc.Equals, "Agent")
switch request {
case "GetEntities":
c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
result := response.(*params.AgentGetEntitiesResults)
result.Entities = []params.AgentGetEntitiesResult{{
Jobs: []multiwatcher.MachineJob{job},
}}
default:
c.Fatalf("not sure how to handle: %q", request)
}
return nil
},
)
w, err := s.manifold.Start(dt.StubGetResource(dt.StubResources{
"agent": dt.StubResource{Output: a},
"api-caller": dt.StubResource{Output: apiCaller},
}))
c.Assert(w, gc.IsNil)
c.Assert(err, gc.Equals, dependency.ErrUninstall)
// State serving info shouldn't have been set for this job type.
c.Assert(a.conf.ssiSet, jc.IsFalse)
}
开发者ID:felicianotech,项目名称:juju,代码行数:28,代码来源:servinginfo_setter_test.go
示例16: TestEntityLookupFailure
func (s *ServingInfoSetterSuite) TestEntityLookupFailure(c *gc.C) {
// Set up a fake Agent and APICaller
a := &mockAgent{}
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, args, response interface{}) error {
c.Assert(objType, gc.Equals, "Agent")
switch request {
case "GetEntities":
c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
result := response.(*params.AgentGetEntitiesResults)
result.Entities = []params.AgentGetEntitiesResult{{
Error: ¶ms.Error{Message: "boom"},
}}
default:
c.Fatalf("not sure how to handle: %q", request)
}
return nil
},
)
// Call the manifold's start func with a fake resource getter that
// returns the fake Agent and APICaller
w, err := s.manifold.Start(dt.StubGetResource(dt.StubResources{
"agent": dt.StubResource{Output: a},
"api-caller": dt.StubResource{Output: apiCaller},
}))
c.Assert(w, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "boom")
}
开发者ID:felicianotech,项目名称:juju,代码行数:28,代码来源:servinginfo_setter_test.go
示例17: SetUpTest
func (s *ManifoldSuite) SetUpTest(c *gc.C) {
spoolDir := c.MkDir()
s.IsolationSuite.SetUpTest(c)
s.factory = &stubMetricFactory{
&testing.Stub{},
spoolDir,
}
testAPIClient := func(apiCaller base.APICaller) metricsadder.MetricsAdderClient {
return newTestAPIMetricSender()
}
s.PatchValue(&sender.NewMetricAdderClient, testAPIClient)
s.manifold = sender.Manifold(sender.ManifoldConfig{
AgentName: "agent",
APICallerName: "api-caller",
MetricSpoolName: "metric-spool",
})
dataDir := c.MkDir()
// create unit agent base dir so that hooks can run.
err := os.MkdirAll(filepath.Join(dataDir, "agents", "unit-u-0"), 0777)
c.Assert(err, jc.ErrorIsNil)
s.getResource = dt.StubGetResource(dt.StubResources{
"agent": dt.StubResource{Output: &dummyAgent{dataDir: dataDir}},
"api-caller": dt.StubResource{Output: &stubAPICaller{&testing.Stub{}}},
"metric-spool": dt.StubResource{Output: s.factory},
})
}
开发者ID:exekias,项目名称:juju,代码行数:30,代码来源:manifold_test.go
示例18: TestStartMissingAgent
func (s *ManifoldSuite) TestStartMissingAgent(c *gc.C) {
getResource := dt.StubGetResource(dt.StubResources{
"agent-name": dt.StubResource{Error: dependency.ErrMissing},
})
worker, err := s.manifold.Start(getResource)
c.Check(worker, gc.IsNil)
c.Check(err, gc.Equals, dependency.ErrMissing)
}
开发者ID:imoapps,项目名称:juju,代码行数:8,代码来源:manifold_test.go
示例19: TestUnlockerMissing
func (*ManifoldSuite) TestUnlockerMissing(c *gc.C) {
resources := resourcesMissing("unlocker")
manifold := discoverspaces.Manifold(namesConfig())
worker, err := manifold.Start(dt.StubGetResource(resources))
c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
c.Check(worker, gc.IsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:manifold_test.go
示例20: TestClockMissing
func (*ManifoldSuite) TestClockMissing(c *gc.C) {
resources := resourcesMissing("clock")
manifold := undertaker.Manifold(namesConfig())
worker, err := manifold.Start(dt.StubGetResource(resources))
c.Check(errors.Cause(err), gc.Equals, dependency.ErrMissing)
c.Check(worker, gc.IsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:8,代码来源:manifold_test.go
注:本文中的github.com/juju/juju/worker/dependency/testing.StubGetResource函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论