* fixed: `identifier` is unused lint error

* make saveMultipleMembersT method saveMultipleMembers

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Mahmudul Haque
2021-02-04 11:38:05 +06:00
коммит произвёл GitHub
родитель 78ccf8a775
Коммит a63dea6c55
62 изменённых файлов: 257 добавлений и 245 удалений

Просмотреть файл

@@ -109,7 +109,8 @@ func channelMemberToSlice(member *model.ChannelMember) []interface{} {
type channelMemberWithSchemeRolesList []channelMemberWithSchemeRoles
func getChannelRoles(schemeGuest, schemeUser, schemeAdmin bool, defaultTeamGuestRole, defaultTeamUserRole, defaultTeamAdminRole, defaultChannelGuestRole, defaultChannelUserRole, defaultChannelAdminRole string, roles []string) rolesInfo {
func getChannelRoles(schemeGuest, schemeUser, schemeAdmin bool, defaultTeamGuestRole, defaultTeamUserRole, defaultTeamAdminRole, defaultChannelGuestRole, defaultChannelUserRole, defaultChannelAdminRole string,
roles []string) rolesInfo {
result := rolesInfo{
roles: []string{},
explicitRoles: []string{},
@@ -606,9 +607,9 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
member2.ChannelId = newChannel.Id
if member1.UserId != member2.UserId {
_, err = s.saveMultipleMembersT(transaction, []*model.ChannelMember{member1, member2})
_, err = s.saveMultipleMembers([]*model.ChannelMember{member1, member2})
} else {
_, err = s.saveMemberT(transaction, member2)
_, err = s.saveMemberT(member2)
}
if err != nil {
return nil, err
@@ -729,6 +730,7 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) (*model.Chan
return &unreadChannel, nil
}
//nolint:unparam
func (s SqlChannelStore) InvalidateChannel(id string) {
}
@@ -739,8 +741,9 @@ func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
}
}
//nolint:unparam
func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, error) {
return s.get(id, false, allowFromCache)
return s.get(id, false)
}
func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
@@ -758,10 +761,10 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, erro
}
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, error) {
return s.get(id, true, false)
return s.get(id, true)
}
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, error) {
func (s SqlChannelStore) get(id string, master bool) (*model.Channel, error) {
var db *gorp.DbMap
if master {
@@ -1392,7 +1395,7 @@ func (s SqlChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]
}
defer finalizeTransaction(transaction)
newMembers, err := s.saveMultipleMembersT(transaction, members)
newMembers, err := s.saveMultipleMembers(members)
if err != nil {
return nil, err
}
@@ -1412,7 +1415,7 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) (*model.Channel
return newMembers[0], nil
}
func (s SqlChannelStore) saveMultipleMembersT(transaction *gorp.Transaction, members []*model.ChannelMember) ([]*model.ChannelMember, error) {
func (s SqlChannelStore) saveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
newChannelMembers := map[string]int{}
users := map[string]bool{}
for _, member := range members {
@@ -1553,8 +1556,8 @@ func (s SqlChannelStore) saveMultipleMembersT(transaction *gorp.Transaction, mem
return newMembers, nil
}
func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *model.ChannelMember) (*model.ChannelMember, error) {
members, err := s.saveMultipleMembersT(transaction, []*model.ChannelMember{member})
func (s SqlChannelStore) saveMemberT(member *model.ChannelMember) (*model.ChannelMember, error) {
members, err := s.saveMultipleMembers([]*model.ChannelMember{member})
if err != nil {
return nil, err
}
@@ -1843,6 +1846,7 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
return props, nil
}
//nolint:unparam
func (s SqlChannelStore) InvalidateMemberCount(channelId string) {
}
@@ -1851,6 +1855,7 @@ func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
return count
}
//nolint:unparam
func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
count, err := s.GetReplica().SelectInt(`
SELECT
@@ -1939,9 +1944,11 @@ func (s SqlChannelStore) GetMemberCountsByGroup(channelID string, includeTimezon
return data, nil
}
//nolint:unparam
func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) {
}
//nolint:unparam
func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
count, err := s.GetReplica().SelectInt(`
SELECT count(*)
@@ -1958,9 +1965,11 @@ func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache boo
return count, nil
}
//nolint:unparam
func (s SqlChannelStore) InvalidateGuestCount(channelId string) {
}
//nolint:unparam
func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
count, err := s.GetReplica().SelectInt(`
SELECT

Просмотреть файл

@@ -324,7 +324,7 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
}
// now we re-order the categories according to the new order
if err = s.updateSidebarCategoryOrderT(transaction, userId, teamId, newOrder); err != nil {
if err = s.updateSidebarCategoryOrderT(transaction, newOrder); err != nil {
return nil, err
}
@@ -541,7 +541,7 @@ func (s SqlChannelStore) GetSidebarCategoryOrder(userId, teamId string) ([]strin
return ids, nil
}
func (s SqlChannelStore) updateSidebarCategoryOrderT(transaction *gorp.Transaction, userId, teamId string, categoryOrder []string) error {
func (s SqlChannelStore) updateSidebarCategoryOrderT(transaction *gorp.Transaction, categoryOrder []string) error {
var newOrder []interface{}
runningOrder := 0
for _, categoryId := range categoryOrder {
@@ -595,7 +595,7 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
}
}
if err = s.updateSidebarCategoryOrderT(transaction, userId, teamId, categoryOrder); err != nil {
if err = s.updateSidebarCategoryOrderT(transaction, categoryOrder); err != nil {
return err
}
@@ -606,6 +606,7 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
return nil
}
//nolint:unparam
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, []*model.SidebarCategoryWithChannels, error) {
transaction, err := s.GetMaster().Begin()
if err != nil {
@@ -943,6 +944,7 @@ func (s SqlChannelStore) DeleteSidebarChannelsByPreferences(preferences *model.P
return nil
}
//nolint:unparam
func (s SqlChannelStore) UpdateSidebarChannelCategoryOnMove(channel *model.Channel, newTeamId string) error {
// if channel is being moved, remove it from the categories, since it's possible that there's no matching category in the new team
if _, err := s.GetMaster().Exec("DELETE FROM SidebarChannels WHERE ChannelId=:ChannelId", map[string]interface{}{"ChannelId": channel.Id}); err != nil {

Просмотреть файл

@@ -58,11 +58,11 @@ func (es SqlEmojiStore) Save(emoji *model.Emoji) (*model.Emoji, error) {
}
func (es SqlEmojiStore) Get(id string, allowFromCache bool) (*model.Emoji, error) {
return es.getBy("Id", id, allowFromCache)
return es.getBy("Id", id)
}
func (es SqlEmojiStore) GetByName(name string, allowFromCache bool) (*model.Emoji, error) {
return es.getBy("Name", name, allowFromCache)
return es.getBy("Name", name)
}
func (es SqlEmojiStore) GetMultipleByName(names []string) ([]*model.Emoji, error) {
@@ -146,7 +146,7 @@ func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) ([]*mode
}
// getBy returns one active (not deleted) emoji, found by any one column (what/key).
func (es SqlEmojiStore) getBy(what, key string, addToCache bool) (*model.Emoji, error) {
func (es SqlEmojiStore) getBy(what, key string) (*model.Emoji, error) {
var emoji *model.Emoji
err := es.GetReplica().SelectOne(&emoji,

Просмотреть файл

@@ -998,7 +998,7 @@ func (s *SqlGroupStore) groupsBySyncableBaseQuery(st model.GroupSyncableType, t
return query
}
func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(st model.GroupSyncableType, teamID string, opts model.GroupSearchOpts) sq.SelectBuilder {
func (s *SqlGroupStore) getGroupsAssociatedToChannelsByTeam(teamID string, opts model.GroupSearchOpts) sq.SelectBuilder {
query := s.getQueryBuilder().
Select("gc.ChannelId, ug.*, gc.SchemeAdmin AS SyncableSchemeAdmin").
From("UserGroups ug").
@@ -1103,7 +1103,7 @@ func (s *SqlGroupStore) GetGroupsByTeam(teamId string, opts model.GroupSearchOpt
}
func (s *SqlGroupStore) GetGroupsAssociatedToChannelsByTeam(teamId string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, error) {
query := s.getGroupsAssociatedToChannelsByTeam(model.GroupSyncableTypeTeam, teamId, opts)
query := s.getGroupsAssociatedToChannelsByTeam(teamId, opts)
if opts.PageOpts != nil {
offset := uint64(opts.PageOpts.Page * opts.PageOpts.PerPage)

Просмотреть файл

@@ -297,7 +297,7 @@ func createStatus(ss store.Store, userId string) *model.Status {
return &m
}
func createTeam(ss store.Store, userId string) *model.Team {
func createTeam(ss store.Store) *model.Team {
m := model.Team{}
m.DisplayName = "DisplayName"
m.Type = model.TEAM_OPEN
@@ -972,7 +972,7 @@ func TestCheckTeamsTeamMembersIntegrity(t *testing.T) {
})
t.Run("should generate a report with one record", func(t *testing.T) {
team := createTeam(ss, model.NewId())
team := createTeam(ss)
member := createTeamMember(ss, team.Id, model.NewId())
dbmap.Delete(team)
result := checkTeamsTeamMembersIntegrity(store)
@@ -1569,7 +1569,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) {
t.Run("should generate a report with one record", func(t *testing.T) {
user := createUser(ss)
team := createTeam(ss, user.Id)
team := createTeam(ss)
member := createTeamMember(ss, team.Id, user.Id)
dbmap.Delete(user)
result := checkUsersTeamMembersIntegrity(store)

Просмотреть файл

@@ -519,15 +519,18 @@ type etagPosts struct {
UpdateAt int64
}
//nolint:unparam
func (s *SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
}
//nolint:unparam
func (s *SqlPostStore) GetEtag(channelId string, allowFromCache, collapsedThreads bool) string {
q := s.getQueryBuilder().Select("Id", "UpdateAt").From("Posts").Where(sq.Eq{"ChannelId": channelId}).OrderBy("UpdateAt DESC").Limit(1)
if collapsedThreads {
q.Where(sq.Eq{"RootId": ""})
}
sql, args, _ := q.ToSql()
var et etagPosts
err := s.GetReplica().SelectOne(&et, sql, args...)
var result string
@@ -558,7 +561,7 @@ func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) erro
return errors.Wrap(err, "failed to update Posts")
}
return s.cleanupThreads(post.Id, post.RootId, post.UserId, false)
return s.cleanupThreads(post.Id, post.RootId, false)
}
func (s *SqlPostStore) permanentDelete(postId string) error {
@@ -567,7 +570,7 @@ func (s *SqlPostStore) permanentDelete(postId string) error {
if err != nil && err != sql.ErrNoRows {
return errors.Wrapf(err, "failed to get Post with id=%s", postId)
}
if err = s.cleanupThreads(post.Id, post.RootId, post.UserId, true); err != nil {
if err = s.cleanupThreads(post.Id, post.RootId, true); err != nil {
return errors.Wrapf(err, "failed to cleanup threads for Post with id=%s", postId)
}
@@ -592,7 +595,7 @@ func (s *SqlPostStore) permanentDeleteAllCommentByUser(userId string) error {
}
for _, ids := range results {
if err = s.cleanupThreads(ids.Id, ids.RootId, userId, true); err != nil {
if err = s.cleanupThreads(ids.Id, ids.RootId, true); err != nil {
return err
}
}
@@ -648,7 +651,7 @@ func (s *SqlPostStore) PermanentDeleteByChannel(channelId string) error {
}
for _, ids := range results {
if err = s.cleanupThreads(ids.Id, ids.RootId, ids.UserId, true); err != nil {
if err = s.cleanupThreads(ids.Id, ids.RootId, true); err != nil {
return err
}
}
@@ -825,10 +828,12 @@ func (s *SqlPostStore) getPostsSinceCollapsedThreads(options model.GetPostsSince
return s.prepareThreadedResponse(posts, options.CollapsedThreadsExtended, false)
}
//nolint:unparam
func (s *SqlPostStore) GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool) (*model.PostList, error) {
if options.CollapsedThreads {
return s.getPostsSinceCollapsedThreads(options)
}
var posts []*model.Post
replyCountQuery1 := ""
@@ -2026,6 +2031,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
return posts, nil
}
//nolint:unparam
func (s *SqlPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, error) {
// Since we don't support paging for DB search, we just return nothing for later pages
if page > 0 {
@@ -2093,7 +2099,7 @@ func (s *SqlPostStore) GetOldestEntityCreationTime() (int64, error) {
return oldest, nil
}
func (s *SqlPostStore) cleanupThreads(postId, rootId, userId string, permanent bool) error {
func (s *SqlPostStore) cleanupThreads(postId, rootId string, permanent bool) error {
if permanent {
if _, err := s.GetMaster().Exec("DELETE FROM Threads WHERE PostId = :Id", map[string]interface{}{"Id": postId}); err != nil {
return errors.Wrap(err, "failed to delete Threads")

Просмотреть файл

@@ -1055,7 +1055,7 @@ func (s SqlTeamStore) GetMembers(teamId string, offset int, limit int, teamMembe
query = query.OrderBy(model.USERNAME)
}
query = applyTeamMemberViewRestrictionsFilter(query, teamId, teamMembersGetOptions.ViewRestrictions)
query = applyTeamMemberViewRestrictionsFilter(query, teamMembersGetOptions.ViewRestrictions)
}
queryString, args, err := query.ToSql()
@@ -1082,7 +1082,7 @@ func (s SqlTeamStore) GetTotalMemberCount(teamId string, restrictions *model.Vie
Where("TeamMembers.UserId = Users.Id").
Where(sq.Eq{"TeamMembers.TeamId": teamId})
query = applyTeamMemberViewRestrictionsFilterForStats(query, teamId, restrictions)
query = applyTeamMemberViewRestrictionsFilterForStats(query, restrictions)
queryString, args, err := query.ToSql()
if err != nil {
return int64(0), errors.Wrap(err, "team_tosql")
@@ -1106,7 +1106,7 @@ func (s SqlTeamStore) GetActiveMemberCount(teamId string, restrictions *model.Vi
Where("Users.DeleteAt = 0").
Where(sq.Eq{"TeamMembers.TeamId": teamId})
query = applyTeamMemberViewRestrictionsFilterForStats(query, teamId, restrictions)
query = applyTeamMemberViewRestrictionsFilterForStats(query, restrictions)
queryString, args, err := query.ToSql()
if err != nil {
return 0, errors.Wrap(err, "team_tosql")
@@ -1132,7 +1132,7 @@ func (s SqlTeamStore) GetMembersByIds(teamId string, userIds []string, restricti
Where(sq.Eq{"TeamMembers.UserId": userIds}).
Where(sq.Eq{"TeamMembers.DeleteAt": 0})
query = applyTeamMemberViewRestrictionsFilter(query, teamId, restrictions)
query = applyTeamMemberViewRestrictionsFilter(query, restrictions)
queryString, args, err := query.ToSql()
if err != nil {
@@ -1408,6 +1408,7 @@ func (s SqlTeamStore) ResetAllTeamSchemes() error {
func (s SqlTeamStore) ClearCaches() {}
// InvalidateAllTeamIdsForUser does not execute anything because the store does not handle the cache.
//nolint:unparam
func (s SqlTeamStore) InvalidateAllTeamIdsForUser(userId string) {}
// ClearAllCustomRoleAssignments removes all custom role assignments from TeamMembers.
@@ -1505,6 +1506,7 @@ func (s SqlTeamStore) GetAllForExportAfter(limit int, afterId string) ([]*model.
}
// GetUserTeamIds get the team ids to which the user belongs to. allowFromCache parameter does not have any effect in this Store
//nolint:unparam
func (s SqlTeamStore) GetUserTeamIds(userId string, allowFromCache bool) ([]string, error) {
var teamIds []string
query, args, err := s.getQueryBuilder().
@@ -1585,7 +1587,7 @@ func (s SqlTeamStore) UpdateMembersRole(teamID string, userIDs []string) error {
return nil
}
func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, teamId string, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
if restrictions == nil {
return query
}
@@ -1615,7 +1617,7 @@ func applyTeamMemberViewRestrictionsFilter(query sq.SelectBuilder, teamId string
return resultQuery.Distinct()
}
func applyTeamMemberViewRestrictionsFilterForStats(query sq.SelectBuilder, teamId string, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
func applyTeamMemberViewRestrictionsFilterForStats(query sq.SelectBuilder, restrictions *model.ViewUsersRestrictions) sq.SelectBuilder {
if restrictions == nil {
return query
}

Просмотреть файл

@@ -36,7 +36,7 @@ func cleanupChannels(t *testing.T, ss store.Store) {
}
func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
createDefaultRoles(t, ss)
createDefaultRoles(ss)
t.Run("Save", func(t *testing.T) { testChannelStoreSave(t, ss) })
t.Run("SaveDirectChannel", func(t *testing.T) { testChannelStoreSaveDirectChannel(t, ss, s) })
@@ -79,7 +79,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
t.Run("GetMemberCountsByGroup", func(t *testing.T) { testGetMemberCountsByGroup(t, ss) })
t.Run("GetGuestCount", func(t *testing.T) { testGetGuestCount(t, ss) })
t.Run("SearchMore", func(t *testing.T) { testChannelStoreSearchMore(t, ss) })
t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss, s) })
t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss) })
t.Run("SearchArchivedInTeam", func(t *testing.T) { testChannelStoreSearchArchivedInTeam(t, ss, s) })
t.Run("SearchForUserInTeam", func(t *testing.T) { testChannelStoreSearchForUserInTeam(t, ss) })
t.Run("SearchAllChannels", func(t *testing.T) { testChannelStoreSearchAllChannels(t, ss) })
@@ -107,7 +107,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlStore) {
t.Run("CreateSidebarCategory", func(t *testing.T) { testCreateSidebarCategory(t, ss) })
t.Run("GetSidebarCategory", func(t *testing.T) { testGetSidebarCategory(t, ss, s) })
t.Run("GetSidebarCategories", func(t *testing.T) { testGetSidebarCategories(t, ss) })
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss, s) })
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss) })
t.Run("DeleteSidebarCategory", func(t *testing.T) { testDeleteSidebarCategory(t, ss, s) })
t.Run("UpdateSidebarChannelsByPreferences", func(t *testing.T) { testUpdateSidebarChannelsByPreferences(t, ss) })
}
@@ -4971,7 +4971,7 @@ func testChannelStoreSearchArchivedInTeam(t *testing.T, ss store.Store, s SqlSto
})
}
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store, s SqlStore) {
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
teamId := model.NewId()
otherTeamId := model.NewId()

Просмотреть файл

@@ -21,8 +21,9 @@ func TestChannelStoreCategories(t *testing.T, ss store.Store, s SqlStore) {
t.Run("CreateSidebarCategory", func(t *testing.T) { testCreateSidebarCategory(t, ss) })
t.Run("GetSidebarCategory", func(t *testing.T) { testGetSidebarCategory(t, ss, s) })
t.Run("GetSidebarCategories", func(t *testing.T) { testGetSidebarCategories(t, ss) })
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss, s) })
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss) })
t.Run("ClearSidebarOnTeamLeave", func(t *testing.T) { testClearSidebarOnTeamLeave(t, ss, s) })
t.Run("UpdateSidebarCategories", func(t *testing.T) { testUpdateSidebarCategories(t, ss) })
t.Run("DeleteSidebarCategory", func(t *testing.T) { testDeleteSidebarCategory(t, ss, s) })
t.Run("UpdateSidebarChannelsByPreferences", func(t *testing.T) { testUpdateSidebarChannelsByPreferences(t, ss) })
}
@@ -869,7 +870,7 @@ func testGetSidebarCategories(t *testing.T, ss store.Store) {
})
}
func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlStore) {
func testUpdateSidebarCategories(t *testing.T, ss store.Store) {
t.Run("ensure the query to update SidebarCategories hasn't been polluted by UpdateSidebarCategoryOrder", func(t *testing.T) {
userId := model.NewId()
teamId := model.NewId()

Просмотреть файл

@@ -15,10 +15,10 @@ import (
)
func TestPluginStore(t *testing.T, ss store.Store, s SqlStore) {
t.Run("SaveOrUpdate", func(t *testing.T) { testPluginSaveOrUpdate(t, ss, s) })
t.Run("CompareAndSet", func(t *testing.T) { testPluginCompareAndSet(t, ss, s) })
t.Run("CompareAndDelete", func(t *testing.T) { testPluginCompareAndDelete(t, ss, s) })
t.Run("SetWithOptions", func(t *testing.T) { testPluginSetWithOptions(t, ss, s) })
t.Run("SaveOrUpdate", func(t *testing.T) { testPluginSaveOrUpdate(t, ss) })
t.Run("CompareAndSet", func(t *testing.T) { testPluginCompareAndSet(t, ss) })
t.Run("CompareAndDelete", func(t *testing.T) { testPluginCompareAndDelete(t, ss) })
t.Run("SetWithOptions", func(t *testing.T) { testPluginSetWithOptions(t, ss) })
t.Run("Get", func(t *testing.T) { testPluginGet(t, ss) })
t.Run("Delete", func(t *testing.T) { testPluginDelete(t, ss) })
t.Run("DeleteAllForPlugin", func(t *testing.T) { testPluginDeleteAllForPlugin(t, ss) })
@@ -63,7 +63,7 @@ func setupKVs(t *testing.T, ss store.Store) (string, func()) {
}
}
func doTestPluginSaveOrUpdate(t *testing.T, ss store.Store, s SqlStore, doer func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error)) {
func doTestPluginSaveOrUpdate(t *testing.T, ss store.Store, doer func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error)) {
t.Run("invalid kv", func(t *testing.T) {
_, tearDown := setupKVs(t, ss)
defer tearDown()
@@ -219,15 +219,15 @@ func doTestPluginSaveOrUpdate(t *testing.T, ss store.Store, s SqlStore, doer fun
})
}
func testPluginSaveOrUpdate(t *testing.T, ss store.Store, s SqlStore) {
doTestPluginSaveOrUpdate(t, ss, s, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
func testPluginSaveOrUpdate(t *testing.T, ss store.Store) {
doTestPluginSaveOrUpdate(t, ss, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
return ss.Plugin().SaveOrUpdate(kv)
})
}
// doTestPluginCompareAndSet exercises the CompareAndSet functionality, but abstracts the actual
// call to same to allow reuse with SetWithOptions
func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compareAndSet func(kv *model.PluginKeyValue, oldValue []byte) (bool, error)) {
func doTestPluginCompareAndSet(t *testing.T, ss store.Store, compareAndSet func(kv *model.PluginKeyValue, oldValue []byte) (bool, error)) {
t.Run("invalid kv", func(t *testing.T) {
_, tearDown := setupKVs(t, ss)
defer tearDown()
@@ -419,7 +419,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
}
for description, setToSameValue := range testCases {
makeKV := func(t *testing.T, existingKV *model.PluginKeyValue) *model.PluginKeyValue {
makeKV := func(existingKV *model.PluginKeyValue) *model.PluginKeyValue {
kv := &model.PluginKeyValue{
PluginId: existingKV.PluginId,
Key: existingKV.Key,
@@ -446,7 +446,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
existingKV, tearDown := setup(t)
defer tearDown()
kv := makeKV(t, existingKV)
kv := makeKV(existingKV)
assertUnchanged(t, kv, existingKV, oldValue)
})
}
@@ -456,7 +456,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
existingKV, tearDown := setup(t)
defer tearDown()
kv := makeKV(t, existingKV)
kv := makeKV(existingKV)
assertChanged(t, kv, existingKV.Value)
})
@@ -465,7 +465,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
existingKV, tearDown := setup(t)
defer tearDown()
kv := makeKV(t, existingKV)
kv := makeKV(existingKV)
kv.ExpireAt = model.GetMillis() + 15*1000
assertChanged(t, kv, existingKV.Value)
@@ -475,7 +475,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
existingKV, tearDown := setup(t)
defer tearDown()
kv := makeKV(t, existingKV)
kv := makeKV(existingKV)
kv.ExpireAt = model.GetMillis() - 15*1000
assertRemoved(t, kv, existingKV.Value)
@@ -484,7 +484,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
}
t.Run("setting a nil value", func(t *testing.T) {
makeKV := func(t *testing.T, existingKV *model.PluginKeyValue) *model.PluginKeyValue {
makeKV := func(existingKV *model.PluginKeyValue) *model.PluginKeyValue {
kv := &model.PluginKeyValue{
PluginId: existingKV.PluginId,
Key: existingKV.Key,
@@ -507,7 +507,7 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
existingKV, tearDown := setup(t)
defer tearDown()
kv := makeKV(t, existingKV)
kv := makeKV(existingKV)
assertUnchanged(t, kv, existingKV, oldValue)
})
}
@@ -517,20 +517,20 @@ func doTestPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore, compare
existingKV, tearDown := setup(t)
defer tearDown()
kv := makeKV(t, existingKV)
kv := makeKV(existingKV)
assertRemoved(t, kv, existingKV.Value)
})
})
})
}
func testPluginCompareAndSet(t *testing.T, ss store.Store, s SqlStore) {
doTestPluginCompareAndSet(t, ss, s, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
func testPluginCompareAndSet(t *testing.T, ss store.Store) {
doTestPluginCompareAndSet(t, ss, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
return ss.Plugin().CompareAndSet(kv, oldValue)
})
}
func testPluginCompareAndDelete(t *testing.T, ss store.Store, s SqlStore) {
func testPluginCompareAndDelete(t *testing.T, ss store.Store) {
t.Run("invalid kv", func(t *testing.T) {
_, tearDown := setupKVs(t, ss)
defer tearDown()
@@ -660,7 +660,7 @@ func testPluginCompareAndDelete(t *testing.T, ss store.Store, s SqlStore) {
})
}
func testPluginSetWithOptions(t *testing.T, ss store.Store, s SqlStore) {
func testPluginSetWithOptions(t *testing.T, ss store.Store) {
t.Run("invalid options", func(t *testing.T) {
_, tearDown := setupKVs(t, ss)
defer tearDown()
@@ -699,7 +699,7 @@ func testPluginSetWithOptions(t *testing.T, ss store.Store, s SqlStore) {
})
t.Run("atomic", func(t *testing.T) {
doTestPluginCompareAndSet(t, ss, s, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
doTestPluginCompareAndSet(t, ss, func(kv *model.PluginKeyValue, oldValue []byte) (bool, error) {
now := model.GetMillis()
options := model.PluginKVSetOptions{
Atomic: true,
@@ -715,7 +715,7 @@ func testPluginSetWithOptions(t *testing.T, ss store.Store, s SqlStore) {
})
t.Run("non-atomic", func(t *testing.T) {
doTestPluginSaveOrUpdate(t, ss, s, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
doTestPluginSaveOrUpdate(t, ss, func(kv *model.PluginKeyValue) (*model.PluginKeyValue, error) {
now := model.GetMillis()
options := model.PluginKVSetOptions{
Atomic: false,

Просмотреть файл

@@ -361,7 +361,7 @@ func testRoleStorePermanentDeleteAll(t *testing.T, ss store.Store) {
}
func testRoleStoreLowerScopedChannelSchemeRoles(t *testing.T, ss store.Store) {
createDefaultRoles(t, ss)
createDefaultRoles(ss)
teamScheme1 := &model.Scheme{
DisplayName: model.NewId(),

Просмотреть файл

@@ -14,7 +14,7 @@ import (
)
func TestSchemeStore(t *testing.T, ss store.Store) {
createDefaultRoles(t, ss)
createDefaultRoles(ss)
t.Run("Save", func(t *testing.T) { testSchemeStoreSave(t, ss) })
t.Run("Get", func(t *testing.T) { testSchemeStoreGet(t, ss) })
@@ -26,7 +26,7 @@ func TestSchemeStore(t *testing.T, ss store.Store) {
t.Run("CountWithoutPermission", func(t *testing.T) { testCountWithoutPermission(t, ss) })
}
func createDefaultRoles(t *testing.T, ss store.Store) {
func createDefaultRoles(ss store.Store) {
ss.Role().Save(&model.Role{
Name: model.TEAM_ADMIN_ROLE_ID,
DisplayName: model.TEAM_ADMIN_ROLE_ID,

Просмотреть файл

@@ -26,7 +26,7 @@ func cleanupTeamStore(t *testing.T, ss store.Store) {
}
func TestTeamStore(t *testing.T, ss store.Store) {
createDefaultRoles(t, ss)
createDefaultRoles(ss)
t.Run("Save", func(t *testing.T) { testTeamStoreSave(t, ss) })
t.Run("Update", func(t *testing.T) { testTeamStoreUpdate(t, ss) })