func (s *EnvironmentCommandSuite) TestEnvironCommandInitErrors(c *gc.C) {
	envPath := gitjujutesting.HomePath(".juju", "environments.yaml")
	err := os.Remove(envPath)
	c.Assert(err, gc.IsNil)
	cmd, _ := prepareEnvCommand(c, "")
	err = cmd.Init(nil)
	c.Assert(err, jc.Satisfies, environs.IsNoEnv)

	// If there are multiple environments but no default,
	// an error should be returned.
	coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfigNoDefault)
	cmd, _ = prepareEnvCommand(c, "")
	err = cmd.Init(nil)
	c.Assert(err, gc.Equals, envcmd.ErrNoEnvironmentSpecified)
}
func (s *EnvironmentCommandSuite) TestEnvironCommandInit(c *gc.C) {
	// Take environment name from command line arg.
	cmd, envName := prepareEnvCommand(c, "explicit")
	err := cmd.Init(nil)
	c.Assert(err, gc.IsNil)
	c.Assert(*envName, gc.Equals, "explicit")

	// Take environment name from the default.
	coretesting.WriteEnvironments(c, coretesting.MultipleEnvConfig)
	testEnsureEnvName(c, coretesting.SampleEnvName)

	// Take environment name from the one and only environment,
	// even if it is not explicitly marked as default.
	coretesting.WriteEnvironments(c, coretesting.SingleEnvConfigNoDefault)
	testEnsureEnvName(c, coretesting.SampleEnvName)

	// If there is a current-environment file, use that.
	err = envcmd.WriteCurrentEnvironment("fubar")
	testEnsureEnvName(c, "fubar")
}
func testEnsureEnvName(c *gc.C, expect string) {
	cmd, envName := prepareEnvCommand(c, "")
	err := cmd.Init(nil)
	c.Assert(err, gc.IsNil)
	c.Assert(*envName, gc.Equals, expect)
}