Example #1
0
func (s *ModelCommandSuite) TestGetDefaultModelCurrentModelSet(c *gc.C) {
	err := modelcmd.WriteCurrentModel("fubar")
	c.Assert(err, jc.ErrorIsNil)
	env, err := modelcmd.GetDefaultModel()
	c.Assert(env, gc.Equals, "fubar")
	c.Assert(err, jc.ErrorIsNil)
}
Example #2
0
func (s *ModelCommandSuite) TestGetDefaultModelBothSet(c *gc.C) {
	os.Setenv(osenv.JujuModelEnvKey, "magic")
	err := modelcmd.WriteCurrentModel("fubar")
	c.Assert(err, jc.ErrorIsNil)
	env, err := modelcmd.GetDefaultModel()
	c.Assert(env, gc.Equals, "magic")
	c.Assert(err, jc.ErrorIsNil)
}
Example #3
0
func (s *ModelCommandSuite) TestGetDefaultModelNothingSet(c *gc.C) {
	envPath := gitjujutesting.JujuXDGDataHomePath("environments.yaml")
	err := os.Remove(envPath)
	c.Assert(err, jc.ErrorIsNil)
	env, err := modelcmd.GetDefaultModel()
	c.Assert(env, gc.Equals, "")
	c.Assert(err, jc.ErrorIsNil)
}
Example #4
0
// switchEnvironment changes the default environment to the given name and
// return, if set, the current default environment name.
func switchEnvironment(envName string) (string, error) {
	if defaultEnv := os.Getenv(osenv.JujuModelEnvKey); defaultEnv != "" {
		return "", errors.Errorf("cannot switch when %s is overriding the model (set to %q)", osenv.JujuModelEnvKey, defaultEnv)
	}
	currentEnv, err := modelcmd.GetDefaultModel()
	if err != nil {
		return "", errors.Annotate(err, "cannot get the default model")
	}
	if err := modelcmd.WriteCurrentModel(envName); err != nil {
		return "", errors.Trace(err)
	}
	return currentEnv, nil
}
Example #5
0
func (s *ModelCommandSuite) TestGetDefaultModel(c *gc.C) {
	env, err := modelcmd.GetDefaultModel()
	c.Assert(env, gc.Equals, "erewhemos")
	c.Assert(err, jc.ErrorIsNil)
}