func (s *macaroonLoginSuite) TestsUnknownUserLogin(c *gc.C) { s.DischargerLogin = func() string { return "testUnknown@nowhere" } cmd := modelcmd.NewModelCommandBase(s.store, s.controllerName, s.accountName, s.modelName) _, err := cmd.NewAPIRoot() c.Assert(err, gc.ErrorMatches, "connecting with cached addresses: invalid entity name or password \\(unauthorized access\\)") }
func (s *macaroonLoginSuite) TestsSuccessfulLogin(c *gc.C) { s.DischargerLogin = func() string { return testUser } cmd := modelcmd.NewModelCommandBase(s.store, s.controllerName, s.accountName, s.modelName) _, err := cmd.NewAPIRoot() c.Assert(err, jc.ErrorIsNil) }
func (s *macaroonLoginSuite) TestsFailToObtainDischargeLogin(c *gc.C) { s.DischargerLogin = func() string { return "" } cmd := modelcmd.NewModelCommandBase(s.store, s.controllerName, s.accountName, s.modelName) _, err := cmd.NewAPIRoot() c.Assert(err, gc.ErrorMatches, "connecting with cached addresses: cannot get discharge.*") }
func (s *macaroonLoginSuite) TestsSuccessfulLogin(c *gc.C) { s.DischargerLogin = func() string { return testUser } cmd := modelcmd.NewModelCommandBase(s.envName, nil, nil) _, err := cmd.NewAPIRoot() c.Assert(err, jc.ErrorIsNil) }
func (s *EnvConfigSuite) TestConfigEnvDoesntExist(c *gc.C) { cmd := modelcmd.NewModelCommandBase("dummy", s.client, nil) s.writeStore(c, false) _, err := cmd.Config(s.store, nil) c.Assert(err, jc.Satisfies, errors.IsNotFound) c.Check(s.client.getCalled, jc.IsFalse) c.Check(s.client.closeCalled, jc.IsFalse) }
func (s *EnvConfigSuite) TestConfigWithNoBootstrapWithClientErr(c *gc.C) { cmd := modelcmd.NewModelCommandBase(s.envName, s.client, errors.New("problem opening connection")) s.writeStore(c, false) _, err := cmd.Config(s.store, nil) c.Assert(err, gc.ErrorMatches, "problem opening connection") c.Check(s.client.getCalled, jc.IsFalse) c.Check(s.client.closeCalled, jc.IsFalse) }
func (s *macaroonLoginSuite) TestsUnknownUserLogin(c *gc.C) { s.DischargerLogin = func() string { return "testUnknown@nowhere" } cmd := modelcmd.NewModelCommandBase(s.envName, nil, nil) _, err := cmd.NewAPIRoot() // TODO(rog) is this really the right error here? c.Assert(err, gc.ErrorMatches, `model "`+s.envName+`" not found`) }
func (s *EnvConfigSuite) TestConfigWithNoBootstrapWithEnvGetError(c *gc.C) { cmd := modelcmd.NewModelCommandBase(s.envName, s.client, nil) s.writeStore(c, false) s.client.err = errors.New("problem getting model attributes") _, err := cmd.Config(s.store, nil) c.Assert(err, gc.ErrorMatches, "problem getting model attributes") c.Check(s.client.getCalled, jc.IsTrue) c.Check(s.client.closeCalled, jc.IsTrue) }
func (s *EnvConfigSuite) TestConfigWithNoBootstrapNoClient(c *gc.C) { cmd := modelcmd.NewModelCommandBase(s.envName, s.client, nil) s.writeStore(c, false) cfg, err := cmd.Config(s.store, nil) c.Assert(err, jc.ErrorIsNil) c.Check(cfg.Name(), gc.Equals, s.envName) c.Check(s.client.getCalled, jc.IsTrue) c.Check(s.client.closeCalled, jc.IsTrue) }
func (s *BaseCommandSuite) assertUnknownModel(c *gc.C, current, expectedCurrent string) { s.store.Models["foo"].CurrentModel = current apiOpen := func(*api.Info, api.DialOpts) (api.Connection, error) { return nil, errors.Trace(¶ms.Error{Code: params.CodeModelNotFound, Message: "model deaddeaf not found"}) } cmd := modelcmd.NewModelCommandBase(s.store, "foo", "admin@local/badmodel") cmd.SetAPIOpen(apiOpen) conn, err := cmd.NewAPIRoot() c.Assert(conn, gc.IsNil) msg := strings.Replace(err.Error(), "\n", "", -1) c.Assert(msg, gc.Equals, `model "admin@local/badmodel" has been removed from the controller, run 'juju models' and switch to one of them.There are 1 accessible models on controller "foo".`) c.Assert(s.store.Models["foo"].Models, gc.HasLen, 1) c.Assert(s.store.Models["foo"].Models["admin@local/goodmodel"], gc.DeepEquals, jujuclient.ModelDetails{"deadbeef2"}) c.Assert(s.store.Models["foo"].CurrentModel, gc.Equals, expectedCurrent) }