func stubCallNames(stub *jujutesting.Stub) []string { var out []string for _, call := range stub.Calls() { out = append(out, call.FuncName) } return out }
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) }
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"}}, }, }) } }
// 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...) } }
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]) }
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") } }
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}) } }