func (s *ModelCommandSuite) TestGetCurrentModelNothingSet(c *gc.C) { err := modelcmd.WriteCurrentController("") c.Assert(err, jc.ErrorIsNil) env, err := modelcmd.GetCurrentModel(s.store) c.Assert(env, gc.Equals, "") c.Assert(err, jc.ErrorIsNil) }
func (s *ModelCommandSuite) TestGetCurrentModelCurrentControllerAccountModel(c *gc.C) { err := s.store.UpdateModel("foo", "bar@baz", "mymodel", jujuclient.ModelDetails{"uuid"}) c.Assert(err, jc.ErrorIsNil) err = s.store.SetCurrentModel("foo", "bar@baz", "mymodel") c.Assert(err, jc.ErrorIsNil) env, err := modelcmd.GetCurrentModel(s.store) c.Assert(err, jc.ErrorIsNil) c.Assert(env, gc.Equals, "mymodel") }
func (s *ModelCommandSuite) TestGetCurrentModelBothSet(c *gc.C) { os.Setenv(osenv.JujuModelEnvKey, "magic") err := s.store.UpdateModel("foo", "bar@baz", "mymodel", jujuclient.ModelDetails{"uuid"}) c.Assert(err, jc.ErrorIsNil) err = s.store.SetCurrentModel("foo", "bar@baz", "mymodel") c.Assert(err, jc.ErrorIsNil) env, err := modelcmd.GetCurrentModel(s.store) c.Assert(err, jc.ErrorIsNil) c.Assert(env, gc.Equals, "magic") }
// Init implements Command.Init. func (c *showModelCommand) Init(args []string) error { if len(args) > 0 { c.SetModelName(args[0]) args = args[1:] } if err := c.ModelCommandBase.Init(args); err != nil { return err } if c.ModelName() == "" { defaultModel, err := modelcmd.GetCurrentModel(c.ClientStore()) if err != nil { return err } c.SetModelName(defaultModel) } return nil }
func (s *ModelCommandSuite) TestGetCurrentModelJujuEnvSet(c *gc.C) { os.Setenv(osenv.JujuModelEnvKey, "magic") env, err := modelcmd.GetCurrentModel(s.store) c.Assert(env, gc.Equals, "magic") c.Assert(err, jc.ErrorIsNil) }
func (s *ModelCommandSuite) TestGetCurrentModelCurrentControllerNoCurrentModel(c *gc.C) { env, err := modelcmd.GetCurrentModel(s.store) c.Assert(env, gc.Equals, "") c.Assert(err, jc.ErrorIsNil) }