func (s *ModelsSuite) TestSetCurrentModel(c *gc.C) { err := s.store.SetCurrentModel("kontroll", "admin/admin") c.Assert(err, jc.ErrorIsNil) all, err := jujuclient.ReadModelsFile(jujuclient.JujuModelsPath()) c.Assert(err, jc.ErrorIsNil) c.Assert(all["kontroll"].CurrentModel, gc.Equals, "admin/admin") }
func (s *ModelsFileSuite) TestReadEmptyFile(c *gc.C) { err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("models.yaml"), []byte(""), 0600) c.Assert(err, jc.ErrorIsNil) models, err := jujuclient.ReadModelsFile(jujuclient.JujuModelsPath()) c.Assert(err, jc.ErrorIsNil) c.Assert(models, gc.HasLen, 0) }
func (s *ModelsFileSuite) TestMigrateLegacyLocal(c *gc.C) { err := ioutil.WriteFile(jujuclient.JujuModelsPath(), []byte(testLegacyModelsYAML), 0644) c.Assert(err, jc.ErrorIsNil) models, err := jujuclient.ReadModelsFile(jujuclient.JujuModelsPath()) c.Assert(err, jc.ErrorIsNil) migratedData, err := ioutil.ReadFile(jujuclient.JujuModelsPath()) c.Assert(err, jc.ErrorIsNil) migratedModels, err := jujuclient.ParseModels(migratedData) c.Assert(err, jc.ErrorIsNil) c.Assert(string(migratedData), jc.DeepEquals, testModelsYAML[1:]) c.Assert(migratedModels, jc.DeepEquals, models) }
func (s *ModelsSuite) TestRemoveControllerRemovesModels(c *gc.C) { store := jujuclient.NewFileClientStore() err := store.AddController("kontroll", jujuclient.ControllerDetails{ ControllerUUID: "abc", CACert: "woop", }) c.Assert(err, jc.ErrorIsNil) err = store.RemoveController("kontroll") c.Assert(err, jc.ErrorIsNil) models, err := jujuclient.ReadModelsFile(jujuclient.JujuModelsPath()) c.Assert(err, jc.ErrorIsNil) _, ok := models["admin/kontroll"] c.Assert(ok, jc.IsFalse) // kontroll models are removed }
func (s *ModelsFileSuite) TestReadNoFile(c *gc.C) { models, err := jujuclient.ReadModelsFile("nowhere.yaml") c.Assert(err, jc.ErrorIsNil) c.Assert(models, gc.IsNil) }