chore: refresh gramsrv public release
This commit is contained in:
parent
75cebe8dbf
commit
70b6820474
1274 changed files with 378751 additions and 59919 deletions
68
internal/store/postgres/message_store_testkit_test.go
Normal file
68
internal/store/postgres/message_store_testkit_test.go
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"telesrv/internal/domain"
|
||||
)
|
||||
|
||||
type fixedBoxIDAllocator struct {
|
||||
next int
|
||||
}
|
||||
|
||||
func (a fixedBoxIDAllocator) NextBoxID(context.Context, int64) (int, error) {
|
||||
return a.next, nil
|
||||
}
|
||||
|
||||
func (a fixedBoxIDAllocator) CurrentBoxID(context.Context, int64) (int, error) {
|
||||
return a.next, nil
|
||||
}
|
||||
|
||||
type perUserCounterAllocator struct {
|
||||
mu sync.Mutex
|
||||
values map[int64]int
|
||||
}
|
||||
|
||||
func (a *perUserCounterAllocator) NextBoxID(_ context.Context, userID int64) (int, error) {
|
||||
return a.next(userID), nil
|
||||
}
|
||||
|
||||
func (a *perUserCounterAllocator) CurrentBoxID(_ context.Context, userID int64) (int, error) {
|
||||
return a.current(userID), nil
|
||||
}
|
||||
|
||||
func (a *perUserCounterAllocator) next(userID int64) int {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if a.values == nil {
|
||||
a.values = map[int64]int{}
|
||||
}
|
||||
a.values[userID]++
|
||||
return a.values[userID]
|
||||
}
|
||||
|
||||
func (a *perUserCounterAllocator) current(userID int64) int {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
return a.values[userID]
|
||||
}
|
||||
|
||||
func messageIDs(messages []domain.Message) []int {
|
||||
out := make([]int, 0, len(messages))
|
||||
for _, msg := range messages {
|
||||
out = append(out, msg.ID)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func sameInts(got, want []int) bool {
|
||||
if len(got) != len(want) {
|
||||
return false
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != want[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue