func (s *MigrationExportSuite) TestModelUsers(c *gc.C) { // Make sure we have some last connection times for the admin user, // and create a few other users. lastConnection := state.NowToTheSecond() owner, err := s.State.UserAccess(s.Owner, s.State.ModelTag()) c.Assert(err, jc.ErrorIsNil) err = state.UpdateModelUserLastConnection(s.State, owner, lastConnection) c.Assert(err, jc.ErrorIsNil) bobTag := names.NewUserTag("bob@external") bob, err := s.State.AddModelUser(s.State.ModelUUID(), state.UserAccessSpec{ User: bobTag, CreatedBy: s.Owner, Access: permission.ReadAccess, }) c.Assert(err, jc.ErrorIsNil) err = state.UpdateModelUserLastConnection(s.State, bob, lastConnection) c.Assert(err, jc.ErrorIsNil) model, err := s.State.Export() c.Assert(err, jc.ErrorIsNil) users := model.Users() c.Assert(users, gc.HasLen, 2) exportedBob := users[0] // admin is "test-admin", and results are sorted exportedAdmin := users[1] c.Assert(exportedAdmin.Name(), gc.Equals, s.Owner) c.Assert(exportedAdmin.DisplayName(), gc.Equals, owner.DisplayName) c.Assert(exportedAdmin.CreatedBy(), gc.Equals, s.Owner) c.Assert(exportedAdmin.DateCreated(), gc.Equals, owner.DateCreated) c.Assert(exportedAdmin.LastConnection(), gc.Equals, lastConnection) c.Assert(exportedAdmin.Access(), gc.Equals, "admin") c.Assert(exportedBob.Name(), gc.Equals, bobTag) c.Assert(exportedBob.DisplayName(), gc.Equals, "") c.Assert(exportedBob.CreatedBy(), gc.Equals, s.Owner) c.Assert(exportedBob.DateCreated(), gc.Equals, bob.DateCreated) c.Assert(exportedBob.LastConnection(), gc.Equals, lastConnection) c.Assert(exportedBob.Access(), gc.Equals, "read") }
func (s *MigrationImportSuite) newModelUser(c *gc.C, name string, readOnly bool, lastConnection time.Time) permission.UserAccess { access := permission.AdminAccess if readOnly { access = permission.ReadAccess } user, err := s.State.AddModelUser(s.State.ModelUUID(), state.UserAccessSpec{ User: names.NewUserTag(name), CreatedBy: s.Owner, Access: access, }) c.Assert(err, jc.ErrorIsNil) if !lastConnection.IsZero() { err = state.UpdateModelUserLastConnection(s.State, user, lastConnection) c.Assert(err, jc.ErrorIsNil) } return user }