func (s *AccountsFileSuite) TestReadEmptyFile(c *gc.C) { err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("accounts.yaml"), []byte(""), 0600) c.Assert(err, jc.ErrorIsNil) accounts, err := jujuclient.ReadAccountsFile(jujuclient.JujuAccountsPath()) c.Assert(err, jc.ErrorIsNil) c.Assert(accounts, gc.HasLen, 0) }
func (s *AccountsSuite) TestSetCurrentAccount(c *gc.C) { err := s.store.SetCurrentAccount("kontroll", "admin@local") c.Assert(err, jc.ErrorIsNil) accounts, err := jujuclient.ReadAccountsFile(jujuclient.JujuAccountsPath()) c.Assert(err, jc.ErrorIsNil) c.Assert(accounts["kontroll"].CurrentAccount, gc.Equals, "admin@local") }
func (s *AccountsFileSuite) TestMigrateLegacyLocal(c *gc.C) { err := ioutil.WriteFile(jujuclient.JujuAccountsPath(), []byte(testLegacyAccountsYAML), 0644) c.Assert(err, jc.ErrorIsNil) accounts, err := jujuclient.ReadAccountsFile(jujuclient.JujuAccountsPath()) c.Assert(err, jc.ErrorIsNil) migratedData, err := ioutil.ReadFile(jujuclient.JujuAccountsPath()) c.Assert(err, jc.ErrorIsNil) migratedAccounts, err := jujuclient.ParseAccounts(migratedData) c.Assert(err, jc.ErrorIsNil) c.Assert(string(migratedData), jc.DeepEquals, testAccountsYAML[1:]) c.Assert(migratedAccounts, jc.DeepEquals, accounts) }
func (s *AccountsSuite) TestRemoveControllerRemovesaccounts(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) accounts, err := jujuclient.ReadAccountsFile(jujuclient.JujuAccountsPath()) c.Assert(err, jc.ErrorIsNil) _, ok := accounts["kontroll"] c.Assert(ok, jc.IsFalse) // kontroll accounts are removed }
func (s *AccountsFileSuite) TestReadNoFile(c *gc.C) { accounts, err := jujuclient.ReadAccountsFile("nowhere.yaml") c.Assert(err, jc.ErrorIsNil) c.Assert(accounts, gc.IsNil) }