示例#1
0
func (s *AdminSuite) TestIsAdminEmail(c *gc.C) {
	s.createAdmins(c)
	defer s.deleteAdmins(c)

	for i, t := range []struct {
		should      string
		admin       t.TestAdmin
		expectError string
	}{{
		should: "validate an existing admin",
		admin:  s.admins["bob"],
	}, {
		should:      "not validate a nonexistent admin",
		admin:       t.TestAdmin{Email: "*****@*****.**"},
		expectError: `admin for email [email protected]: user not found`,
	}} {
		c.Logf("test %d: should %s", i, t.should)

		if t.expectError == "" {
			c.Check(admin.IsAdminEmail(s.d, t.admin.Email), jc.ErrorIsNil)
		} else {
			c.Check(admin.IsAdminEmail(s.d, t.admin.Email), gc.ErrorMatches, t.expectError)
		}
	}
}
示例#2
0
func (s *AdminSuite) deleteByEmailTests(adm t.TestAdmin, c *gc.C) error {
	if err := admin.DeleteByEmail(s.d, adm.Email); err != nil {
		c.Logf("failed to delete admin %q", adm.Email)
		return err
	}

	err := admin.IsAdminEmail(s.d, adm.Email)
	c.Assert(err, gc.ErrorMatches, fmt.Sprintf("admin for email %s: user not found", adm.Email))
	return nil
}
示例#3
0
func getAdminEmail(rl *readline.Instance, d db.DB) (string, error) {
	none := ""

	rl.SetPrompt("Enter email: ")
	defer rl.SetPrompt("> ")

	email, err := rl.Readline()
	if err != nil {
		return none, err
	}

	if err := admin.IsAdminEmail(d, email); err != nil {
		if errors.IsUserNotFound(err) {
			return email, nil
		}
		return none, err
	}

	return none, fmt.Errorf("admin %s already exists", email)
}