当前位置: 首页>>代码示例>>Golang>>正文


Golang Stub.SetErrors方法代码示例

本文整理汇总了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")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:12,代码来源:flag_test.go

示例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)
}
开发者ID:imoapps,项目名称:juju,代码行数:24,代码来源:context_test.go

示例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",
	}})

}
开发者ID:mhilton,项目名称:juju,代码行数:24,代码来源:contextfactory_test.go


注:本文中的github.com/juju/testing.Stub.SetErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。