當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Stub.NextErr方法代碼示例

本文整理匯總了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 := &params.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
}
開發者ID:bac,項目名稱:juju,代碼行數:32,代碼來源:connect_test.go

示例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,
	}
}
開發者ID:makyo,項目名稱:juju,代碼行數:16,代碼來源:util_test.go

示例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
	})
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:13,代碼來源:util_test.go

示例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)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:24,代碼來源:context_test.go

示例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()
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:6,代碼來源:fixture_test.go


注:本文中的github.com/juju/testing.Stub.NextErr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。