Exemple #1
0
func (s *usermanagerSuite) TestAddUserResponseError(c *gc.C) {
	usermanager.PatchResponses(s, s.usermanager,
		func(interface{}) error {
			return errors.New("call error")
		},
	)
	_, _, err := s.usermanager.AddUser("foobar", "Foo Bar", "password")
	c.Assert(err, gc.ErrorMatches, "call error")
}
Exemple #2
0
func (s *usermanagerSuite) TestUserInfoNoResults(c *gc.C) {
	usermanager.PatchResponses(s, s.usermanager,
		func(interface{}) error {
			// do nothing, we get an empty result with no error
			return nil
		},
	)
	tag := names.NewLocalUserTag("foobar")
	_, err := s.usermanager.UserInfo(tag.String())
	c.Assert(err, gc.ErrorMatches, "expected 1 result, got 0")
}
Exemple #3
0
func (s *usermanagerSuite) TestAddUserResultCount(c *gc.C) {
	usermanager.PatchResponses(s, s.usermanager,
		func(result interface{}) error {
			if result, ok := result.(*params.AddUserResults); ok {
				result.Results = make([]params.AddUserResult, 2)
				return nil
			}
			return errors.New("wrong result type")
		},
	)
	_, _, err := s.usermanager.AddUser("foobar", "Foo Bar", "password")
	c.Assert(err, gc.ErrorMatches, "expected 1 result, got 2")
}
Exemple #4
0
func (s *usermanagerSuite) TestUserInfoMoreThanOneResult(c *gc.C) {
	usermanager.PatchResponses(s, s.usermanager,
		func(result interface{}) error {
			if result, ok := result.(*ums.UserInfoResults); ok {
				result.Results = make([]ums.UserInfoResult, 2)
			}
			return nil
		},
	)
	tag := names.NewLocalUserTag("foobar")
	_, err := s.usermanager.UserInfo(tag.String())
	c.Assert(err, gc.ErrorMatches, "expected 1 result, got 2")
}
Exemple #5
0
func (s *usermanagerSuite) TestUserInfoMoreThanOneError(c *gc.C) {
	usermanager.PatchResponses(s, s.usermanager,
		func(result interface{}) error {
			if result, ok := result.(*params.UserInfoResults); ok {
				result.Results = make([]params.UserInfoResult, 2)
				result.Results[0].Error = &params.Error{Message: "first error"}
				result.Results[1].Error = &params.Error{Message: "second error"}
				return nil
			}
			return errors.New("wrong result type")
		},
	)
	_, err := s.usermanager.UserInfo([]string{"foo", "bar"}, usermanager.AllUsers)
	c.Assert(err, gc.ErrorMatches, "foo: first error, bar: second error")
}
Exemple #6
0
func (s *usermanagerSuite) TestUserInfoMoreThanOneResult(c *gc.C) {
	usermanager.PatchResponses(s, s.usermanager,
		func(result interface{}) error {
			if result, ok := result.(*params.UserInfoResults); ok {
				result.Results = make([]params.UserInfoResult, 2)
				result.Results[0].Result = &params.UserInfo{Username: "******"}
				result.Results[1].Result = &params.UserInfo{Username: "******"}
				return nil
			}
			return errors.New("wrong result type")
		},
	)
	obtained, err := s.usermanager.UserInfo(nil, usermanager.AllUsers)
	c.Assert(err, jc.ErrorIsNil)

	expected := []params.UserInfo{
		{Username: "******"},
		{Username: "******"},
	}

	c.Assert(obtained, jc.DeepEquals, expected)
}