Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
func (s *AccountsSuite) TestAccountDetailsNoFile(c *gc.C) {
	err := os.Remove(jujuclient.JujuAccountsPath())
	c.Assert(err, jc.ErrorIsNil)
	details, err := s.store.AccountDetails("not-found")
	c.Assert(err, gc.ErrorMatches, "account details for controller not-found not found")
	c.Assert(details, gc.IsNil)
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
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")
}
Exemplo n.º 5
0
func (s *AccountsSuite) TestAllAccountsNoFile(c *gc.C) {
	err := os.Remove(jujuclient.JujuAccountsPath())
	c.Assert(err, jc.ErrorIsNil)
	accounts, err := s.store.AllAccounts("not-found")
	c.Assert(err, gc.ErrorMatches, "accounts for controller not-found not found")
	c.Assert(accounts, gc.HasLen, 0)
}
Exemplo n.º 6
0
func (s *AccountsSuite) TestAccountByNameNoFile(c *gc.C) {
	err := os.Remove(jujuclient.JujuAccountsPath())
	c.Assert(err, jc.ErrorIsNil)
	details, err := s.store.AccountByName("not-found", "admin@local")
	c.Assert(err, gc.ErrorMatches, "controller not-found not found")
	c.Assert(details, gc.IsNil)
}
Exemplo n.º 7
0
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
}
Exemplo n.º 8
0
func (s *AccountsSuite) TestRemoveAccountNoFile(c *gc.C) {
	err := os.Remove(jujuclient.JujuAccountsPath())
	c.Assert(err, jc.ErrorIsNil)
	err = s.store.RemoveAccount("not-found")
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
}