Esempio n. 1
0
func (suite *StateSuite) TestCreateStateFileWritesEmptyStateFile(c *gc.C) {
	stor := suite.newStorage(c)

	url, err := common.CreateStateFile(stor)
	c.Assert(err, jc.ErrorIsNil)

	reader, err := storage.Get(stor, common.StateFile)
	c.Assert(err, jc.ErrorIsNil)
	data, err := ioutil.ReadAll(reader)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(string(data), gc.Equals, "")
	c.Assert(url, gc.NotNil)
	expectedURL, err := stor.URL(common.StateFile)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(url, gc.Equals, expectedURL)
}
Esempio n. 2
0
func (suite *StateSuite) TestDeleteStateFile(c *gc.C) {
	closer, stor, dataDir := envtesting.CreateLocalTestStorage(c)
	defer closer.Close()

	err := common.DeleteStateFile(stor)
	c.Assert(err, jc.ErrorIsNil) // doesn't exist, juju don't care

	_, err = common.CreateStateFile(stor)
	c.Assert(err, jc.ErrorIsNil)
	_, err = os.Stat(filepath.Join(dataDir, common.StateFile))
	c.Assert(err, jc.ErrorIsNil)

	err = common.DeleteStateFile(stor)
	c.Assert(err, jc.ErrorIsNil)
	_, err = os.Stat(filepath.Join(dataDir, common.StateFile))
	c.Assert(err, jc.Satisfies, os.IsNotExist)
}