MCPcopy
hub / github.com/unkeyed/unkey / createRatelimits

Function createRatelimits

pkg/clickhouse/billable_usage_test.go:232–255  ·  view source on GitHub ↗
(workspaceID string, count int, timestamp time.Time, passed bool)

Source from the content-addressed store, hash-verified

230}
231
232func createRatelimits(workspaceID string, count int, timestamp time.Time, passed bool) []schema.Ratelimit {
233 ratelimits := make([]schema.Ratelimit, count)
234 var remaining uint64 = 50
235 if !passed {
236 remaining = 0
237 }
238 for i := range count {
239 ratelimits[i] = schema.Ratelimit{
240 RequestID: uid.New(uid.RequestPrefix),
241 Time: timestamp.Add(time.Duration(i) * time.Second).UnixMilli(),
242 WorkspaceID: workspaceID,
243 NamespaceID: uid.New(uid.RatelimitNamespacePrefix),
244 Identifier: uid.New(uid.IdentityPrefix),
245 Passed: passed,
246 Latency: rand.Float64() * 10,
247 OverrideID: "",
248 Limit: 100,
249 Remaining: remaining,
250 ResetAt: timestamp.Add(time.Minute).UnixMilli(),
251 Tokens: 1,
252 }
253 }
254 return ratelimits
255}
256
257func insertVerifications(t *testing.T, ctx context.Context, conn ch.Conn, verifications []schema.KeyVerification) {
258 if len(verifications) == 0 {

Callers 1

Calls 4

NewFunction · 0.92
Float64Method · 0.80
AddMethod · 0.45
DurationMethod · 0.45

Tested by

no test coverage detected