本文整理汇总了Golang中github.com/juju/testing.Stub.SetErrors方法的典型用法代码示例。如果您正苦于以下问题:Golang Stub.SetErrors方法的具体用法?Golang Stub.SetErrors怎么用?Golang Stub.SetErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/testing.Stub
的用法示例。
在下文中一共展示了Stub.SetErrors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestClaimError
func (s *FlagSuite) TestClaimError(c *gc.C) {
var stub testing.Stub
stub.SetErrors(errors.New("squish"))
worker, err := singular.NewFlagWorker(singular.FlagConfig{
Facade: newStubFacade(&stub),
Clock: &fakeClock{},
Duration: time.Hour,
})
c.Check(worker, gc.IsNil)
c.Check(err, gc.ErrorMatches, "squish")
}
示例2: TestRequestRebootNow
func (s *InterfaceSuite) TestRequestRebootNow(c *gc.C) {
ctx := s.GetContext(c, -1, "").(*context.HookContext)
var stub testing.Stub
var p *mockProcess
p = &mockProcess{func() error {
// Reboot priority should be set before the process
// is killed, or else the client waiting for the
// process to exit will race with the setting of
// the priority.
priority := ctx.GetRebootPriority()
c.Assert(priority, gc.Equals, jujuc.RebootNow)
return stub.NextErr()
}}
stub.SetErrors(errors.New("process is already dead"))
ctx.SetProcess(p)
err := ctx.RequestReboot(jujuc.RebootNow)
c.Assert(err, jc.ErrorIsNil)
// Everything went well, so priority should still be RebootNow.
priority := ctx.GetRebootPriority()
c.Assert(priority, gc.Equals, jujuc.RebootNow)
}
示例3: testLeadershipContextWiring
func (s *ContextFactorySuite) testLeadershipContextWiring(c *gc.C, createContext func() runner.Context) {
var stub testing.Stub
stub.SetErrors(errors.New("bam"))
restore := runner.PatchNewLeadershipContext(
func(accessor runner.LeadershipSettingsAccessor, tracker leadership.Tracker) runner.LeadershipContext {
stub.AddCall("NewLeadershipContext", accessor, tracker)
return &StubLeadershipContext{Stub: &stub}
},
)
defer restore()
ctx := createContext()
isLeader, err := ctx.IsLeader()
c.Check(err, gc.ErrorMatches, "bam")
c.Check(isLeader, jc.IsFalse)
stub.CheckCalls(c, []testing.StubCall{{
FuncName: "NewLeadershipContext",
Args: []interface{}{s.uniter.LeadershipSettings, fakeTracker{}},
}, {
FuncName: "IsLeader",
}})
}