api_key_cache_test.go 783 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //go:build unit
  2. package repository
  3. import (
  4. "math"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestApiKeyRateLimitKey(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. userID int64
  12. expected string
  13. }{
  14. {
  15. name: "normal_user_id",
  16. userID: 123,
  17. expected: "apikey:ratelimit:123",
  18. },
  19. {
  20. name: "zero_user_id",
  21. userID: 0,
  22. expected: "apikey:ratelimit:0",
  23. },
  24. {
  25. name: "negative_user_id",
  26. userID: -1,
  27. expected: "apikey:ratelimit:-1",
  28. },
  29. {
  30. name: "max_int64",
  31. userID: math.MaxInt64,
  32. expected: "apikey:ratelimit:9223372036854775807",
  33. },
  34. }
  35. for _, tc := range tests {
  36. t.Run(tc.name, func(t *testing.T) {
  37. got := apiKeyRateLimitKey(tc.userID)
  38. require.Equal(t, tc.expected, got)
  39. })
  40. }
  41. }