本文整理汇总了Golang中github.com/juju/testing.Stub.Calls方法的典型用法代码示例。如果您正苦于以下问题:Golang Stub.Calls方法的具体用法?Golang Stub.Calls怎么用?Golang Stub.Calls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/testing.Stub
的用法示例。
在下文中一共展示了Stub.Calls方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: stubCallNames
func stubCallNames(stub *jujutesting.Stub) []string {
var out []string
for _, call := range stub.Calls() {
out = append(out, call.FuncName)
}
return out
}
示例2: checkRemovalsMatch
func checkRemovalsMatch(c *gc.C, stub *testing.Stub, expected ...string) {
var completedRemovals []string
for _, call := range stub.Calls() {
if call.FuncName == "CompleteRemoval" {
machineId := call.Args[0].(names.MachineTag).Id()
completedRemovals = append(completedRemovals, machineId)
}
}
c.Check(completedRemovals, gc.DeepEquals, expected)
}
示例3: checkCalls
func checkCalls(c *gc.C, stub *testing.Stub, names ...string) {
stub.CheckCallNames(c, names...)
for _, call := range stub.Calls() {
c.Check(call.Args, jc.DeepEquals, []interface{}{
params.Entities{
[]params.Entity{{"model-some-uuid"}},
},
})
}
}
示例4: CheckMethodCalls
// CheckMethodCalls works like testing.Stub.CheckCalls, but also
// checks the receivers.
func CheckMethodCalls(c *gc.C, stub *testing.Stub, calls ...StubMethodCall) {
receivers := make([]interface{}, len(calls))
for i, call := range calls {
receivers[i] = call.Receiver
}
stub.CheckReceivers(c, receivers...)
c.Check(stub.Calls(), gc.HasLen, len(calls))
for i, call := range calls {
stub.CheckCall(c, i, call.FuncName, call.Args...)
}
}
示例5: assertChangePasswordSuccess
func (*ScaryConnectSuite) assertChangePasswordSuccess(c *gc.C, stub *testing.Stub) {
err := checkChangePassword(c, stub)
c.Check(err, gc.Equals, apicaller.ErrChangedPassword)
stub.CheckCallNames(c,
"Life", "ChangeConfig",
// Be careful, these are two different SetPassword receivers.
"SetPassword", "SetOldPassword", "SetPassword",
"Close",
)
checkSaneChange(c, stub.Calls()[2:5])
}
示例6: TestWatch
func (s *ClientSuite) TestWatch(c *gc.C) {
var stub jujutesting.Stub
apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
stub.AddCall(objType+"."+request, id, arg)
switch request {
case "Watch":
*(result.(*params.NotifyWatchResult)) = params.NotifyWatchResult{
NotifyWatcherId: "abc",
}
case "Next":
// The full success case is tested in api/watcher.
return errors.New("boom")
case "Stop":
}
return nil
})
client := migrationminion.NewClient(apiCaller)
w, err := client.Watch()
c.Assert(err, jc.ErrorIsNil)
defer worker.Stop(w)
errC := make(chan error)
go func() {
errC <- w.Wait()
}()
select {
case err := <-errC:
c.Assert(err, gc.ErrorMatches, "boom")
expectedCalls := []jujutesting.StubCall{
{"Migrationminion.Watch", []interface{}{"", nil}},
{"MigrationStatusWatcher.Next", []interface{}{"abc", nil}},
{"MigrationStatusWatcher.Stop", []interface{}{"abc", nil}},
}
// The Stop API call happens in a separate goroutine which
// might execute after the worker has exited so wait for the
// expected calls to arrive.
for a := coretesting.LongAttempt.Start(); a.Next(); {
if len(stub.Calls()) >= len(expectedCalls) {
return
}
}
stub.CheckCalls(c, expectedCalls)
case <-time.After(coretesting.LongWait):
c.Fatal("timed out waiting for watcher to die")
}
}
示例7: checkCalls
func checkCalls(c *gc.C, stub *testing.Stub, names ...string) {
stub.CheckCallNames(c, names...)
for _, call := range stub.Calls() {
c.Check(call.Args, gc.DeepEquals, []interface{}{testEntity})
}
}