func (s *WhoAmITestSuite) TestFromStoreErr(c *gc.C) { msg := "fail getting current controller" errStore := jujuclienttesting.NewStubStore() errStore.SetErrors(errors.New(msg)) s.store = errStore s.expectedErr = msg s.assertWhoAmIFailed(c) errStore.CheckCallNames(c, "CurrentController") }
func (s *ListControllersSuite) TestListControllersReadFromStoreErr(c *gc.C) { msg := "fail getting all controllers" errStore := jujuclienttesting.NewStubStore() errStore.SetErrors(errors.New(msg)) s.store = errStore s.expectedErr = fmt.Sprintf("failed to list controllers: %v", msg) s.assertListControllersFailed(c) errStore.CheckCallNames(c, "AllControllers") }
func (s *ShowControllerSuite) TestShowControllerReadFromStoreErr(c *gc.C) { s.fakeController.store = s.createTestClientStore(c) msg := "fail getting controller" errStore := jujuclienttesting.NewStubStore() errStore.SetErrors(errors.New(msg)) s.store = errStore s.expectedErr = msg s.assertShowControllerFailed(c, "test1") errStore.CheckCallNames(c, "ControllerByName") }
// In the case where we cannot examine the client store, we want the // error to propagate back up to the user. func (s *BootstrapSuite) TestBootstrapPropagatesStoreErrors(c *gc.C) { const controllerName = "devcontroller" bootstrappedControllerName(controllerName) s.patchVersionAndSeries(c, "raring") store := jujuclienttesting.NewStubStore() store.SetErrors(errors.New("oh noes")) cmd := &bootstrapCommand{} cmd.SetClientStore(store) _, err := coretesting.RunCommand(c, modelcmd.Wrap(cmd), controllerName, "dummy", "--auto-upgrade") c.Assert(err, gc.ErrorMatches, `loading credentials: oh noes`) }
// We create a macaroon, but fail to write it to accounts.yaml. // We should not call SetPassword subsequently. func (s *ChangePasswordCommandSuite) TestNoSetPasswordAfterFailedWrite(c *gc.C) { store := jujuclienttesting.NewStubStore() store.CurrentAccountFunc = func(string) (string, error) { return "account-name", nil } store.AccountByNameFunc = func(string, string) (*jujuclient.AccountDetails, error) { return &jujuclient.AccountDetails{"user", "old-password", ""}, nil } store.ControllerByNameFunc = func(string) (*jujuclient.ControllerDetails, error) { return &jujuclient.ControllerDetails{}, nil } s.store = store store.SetErrors(errors.New("failed to write")) _, err := s.run(c) c.Assert(err, gc.ErrorMatches, "failed to update client credentials: failed to write") s.mockAPI.CheckCallNames(c, "CreateLocalLoginMacaroon") // no SetPassword }