func (s *EnvironmentCommandSuite) TestWriteAddsNewline(c *gc.C) { err := envcmd.WriteCurrentEnvironment("fubar") c.Assert(err, gc.IsNil) current, err := ioutil.ReadFile(envcmd.GetCurrentEnvironmentFilePath()) c.Assert(err, gc.IsNil) c.Assert(string(current), gc.Equals, "fubar\n") }
func (s *filesSuite) TestWriteControllerRemovesEnvironmentFile(c *gc.C) { err := envcmd.WriteCurrentEnvironment("fubar") c.Assert(err, jc.ErrorIsNil) err = envcmd.WriteCurrentController("baz") c.Assert(err, jc.ErrorIsNil) c.Assert(envcmd.GetCurrentEnvironmentFilePath(), jc.DoesNotExist) }
func (*EnvironmentCommandSuite) TestErrorWritingFile(c *gc.C) { // Can't write a file over a directory. os.MkdirAll(envcmd.GetCurrentEnvironmentFilePath(), 0777) err := envcmd.WriteCurrentEnvironment("fubar") c.Assert(err, gc.ErrorMatches, "unable to write to the environment file: .*") }