本文整理汇总了Golang中github.com/juju/testing.Stub.NextErr方法的典型用法代码示例。如果您正苦于以下问题:Golang Stub.NextErr方法的具体用法?Golang Stub.NextErr怎么用?Golang Stub.NextErr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/testing.Stub
的用法示例。
在下文中一共展示了Stub.NextErr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkChangePassword
func checkChangePassword(c *gc.C, stub *testing.Stub) error {
// We prepend the unauth/success pair that triggers password
// change, and consume them in apiOpen below...
//errUnauth := ¶ms.Error{Code: params.CodeUnauthorized}
//allErrs := append([]error{errUnauth, nil}, errs...)
//
//stub := &testing.Stub{}
//stub.SetErrors(allErrs...)
expectConn := &mockConn{stub: stub}
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
// ...but we *don't* record the calls themselves; they
// are tested plenty elsewhere, and hiding them makes
// client code simpler.
if err := stub.NextErr(); err != nil {
return nil, err
}
return expectConn, nil
}
entity := names.NewApplicationTag("omg")
connect := func() (api.Connection, error) {
return apicaller.ScaryConnect(&mockAgent{
stub: stub,
model: coretesting.ModelTag,
entity: entity,
}, apiOpen)
}
conn, err := lifeTest(c, stub, apiagent.Alive, connect)
c.Check(conn, gc.IsNil)
return err
}
示例2: newMockWatcher
// newMockWatcher consumes an error from the supplied testing.Stub, and
// returns a state.NotifyWatcher that either works or doesn't depending
// on whether the error was nil.
func newMockWatcher(stub *testing.Stub) *mockWatcher {
changes := make(chan struct{}, 1)
err := stub.NextErr()
if err == nil {
changes <- struct{}{}
} else {
close(changes)
}
return &mockWatcher{
err: err,
changes: changes,
}
}
示例3: strategyTest
func strategyTest(stub *testing.Stub, strategy utils.AttemptStrategy, test func(api.OpenFunc) (api.Connection, error)) (api.Connection, error) {
unpatch := testing.PatchValue(apicaller.Strategy, strategy)
defer unpatch()
return test(func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
// copy because I don't trust what might happen to info
stub.AddCall("apiOpen", *info, opts)
err := stub.NextErr()
if err != nil {
return nil, err
}
return &mockConn{stub: stub}, nil
})
}
示例4: 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)
}
示例5: mockHandleAction
func mockHandleAction(stub *testing.Stub) func(string, map[string]interface{}) (map[string]interface{}, error) {
return func(name string, params map[string]interface{}) (map[string]interface{}, error) {
stub.AddCall("HandleAction", name)
return nil, stub.NextErr()
}
}