merged from gramsrv upstream
This commit is contained in:
parent
79c64ee916
commit
21a0856587
651 changed files with 54774 additions and 4590 deletions
60
internal/store/memory/channel_members_sparse_test.go
Normal file
60
internal/store/memory/channel_members_sparse_test.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"telesrv/internal/domain"
|
||||
"telesrv/internal/store"
|
||||
)
|
||||
|
||||
func TestFilterActiveChannelMemberPairsKeepsExactEdges(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
channels := NewChannelStore()
|
||||
first, err := channels.CreateChannel(ctx, domain.CreateChannelRequest{
|
||||
CreatorUserID: 1,
|
||||
MemberUserIDs: []int64{11, 12},
|
||||
Title: "first",
|
||||
Megagroup: true,
|
||||
Date: 1700000000,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateChannel(first): %v", err)
|
||||
}
|
||||
second, err := channels.CreateChannel(ctx, domain.CreateChannelRequest{
|
||||
CreatorUserID: 2,
|
||||
MemberUserIDs: []int64{11, 12},
|
||||
Title: "second",
|
||||
Megagroup: true,
|
||||
Date: 1700000001,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateChannel(second): %v", err)
|
||||
}
|
||||
|
||||
got, err := channels.FilterActiveChannelMemberPairs(ctx, map[int64][]int64{
|
||||
first.Channel.ID: {11},
|
||||
second.Channel.ID: {12},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("FilterActiveChannelMemberPairs: %v", err)
|
||||
}
|
||||
if len(got[first.Channel.ID]) != 1 || got[first.Channel.ID][0] != 11 {
|
||||
t.Fatalf("first channel result = %+v, want [11]", got[first.Channel.ID])
|
||||
}
|
||||
if len(got[second.Channel.ID]) != 1 || got[second.Channel.ID][0] != 12 {
|
||||
t.Fatalf("second channel result = %+v, want [12]", got[second.Channel.ID])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterActiveChannelMemberPairsRejectsOverLimit(t *testing.T) {
|
||||
userIDs := make([]int64, store.MaxActiveChannelMemberPairs+1)
|
||||
for i := range userIDs {
|
||||
userIDs[i] = int64(i + 1)
|
||||
}
|
||||
_, err := NewChannelStore().FilterActiveChannelMemberPairs(context.Background(), map[int64][]int64{1: userIDs})
|
||||
if !errors.Is(err, store.ErrActiveChannelMemberPairsLimit) {
|
||||
t.Fatalf("FilterActiveChannelMemberPairs error = %v, want ErrActiveChannelMemberPairsLimit", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue