2023-02-15 01:52:11 +00:00
|
|
|
package logstore_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/logstore"
|
2023-09-15 14:58:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
2023-02-15 01:52:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type emitterOption func(config *logstore.EmitterConfig)
|
|
|
|
|
|
|
|
func emitterConfig(options ...emitterOption) *logstore.EmitterConfig {
|
|
|
|
cfg := &logstore.EmitterConfig{
|
2023-09-15 14:58:45 +00:00
|
|
|
Enabled: true,
|
2023-02-15 01:52:11 +00:00
|
|
|
Debounce: &logstore.DebouncerConfig{
|
|
|
|
MinFrequency: 0,
|
|
|
|
MaxBulkSize: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, opt := range options {
|
|
|
|
opt(cfg)
|
|
|
|
}
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
func withDebouncerConfig(config *logstore.DebouncerConfig) emitterOption {
|
|
|
|
return func(c *logstore.EmitterConfig) {
|
|
|
|
c.Debounce = config
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func withDisabled() emitterOption {
|
|
|
|
return func(c *logstore.EmitterConfig) {
|
|
|
|
c.Enabled = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
type quotaOption func(config *query.Quota)
|
2023-02-15 01:52:11 +00:00
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
func quotaConfig(quotaOptions ...quotaOption) *query.Quota {
|
|
|
|
q := &query.Quota{
|
2023-02-15 01:52:11 +00:00
|
|
|
Amount: 90,
|
|
|
|
Limit: false,
|
|
|
|
ResetInterval: 90 * time.Second,
|
|
|
|
From: time.Unix(0, 0),
|
|
|
|
}
|
|
|
|
for _, opt := range quotaOptions {
|
|
|
|
opt(q)
|
|
|
|
}
|
2023-09-15 14:58:45 +00:00
|
|
|
return q
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func withAmountAndInterval(n uint64) quotaOption {
|
2023-09-15 14:58:45 +00:00
|
|
|
return func(c *query.Quota) {
|
2023-02-15 01:52:11 +00:00
|
|
|
c.Amount = n
|
|
|
|
c.ResetInterval = time.Duration(n) * time.Second
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func withLimiting() quotaOption {
|
2023-09-15 14:58:45 +00:00
|
|
|
return func(c *query.Quota) {
|
2023-02-15 01:52:11 +00:00
|
|
|
c.Limit = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func repeat(value, times int) []int {
|
|
|
|
ints := make([]int, times)
|
|
|
|
for i := 0; i < times; i++ {
|
|
|
|
ints[i] = value
|
|
|
|
}
|
|
|
|
return ints
|
|
|
|
}
|
|
|
|
|
|
|
|
func uint64Ptr(n uint64) *uint64 { return &n }
|