account_pool_mode_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //go:build unit
  2. package service
  3. import (
  4. "encoding/json"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestGetPoolModeRetryCount(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. account *Account
  12. expected int
  13. }{
  14. {
  15. name: "default_when_not_pool_mode",
  16. account: &Account{
  17. Type: AccountTypeAPIKey,
  18. Platform: PlatformOpenAI,
  19. Credentials: map[string]any{},
  20. },
  21. expected: defaultPoolModeRetryCount,
  22. },
  23. {
  24. name: "default_when_missing_retry_count",
  25. account: &Account{
  26. Type: AccountTypeAPIKey,
  27. Platform: PlatformOpenAI,
  28. Credentials: map[string]any{
  29. "pool_mode": true,
  30. },
  31. },
  32. expected: defaultPoolModeRetryCount,
  33. },
  34. {
  35. name: "supports_float64_from_json_credentials",
  36. account: &Account{
  37. Type: AccountTypeAPIKey,
  38. Platform: PlatformOpenAI,
  39. Credentials: map[string]any{
  40. "pool_mode": true,
  41. "pool_mode_retry_count": float64(5),
  42. },
  43. },
  44. expected: 5,
  45. },
  46. {
  47. name: "supports_json_number",
  48. account: &Account{
  49. Type: AccountTypeAPIKey,
  50. Platform: PlatformOpenAI,
  51. Credentials: map[string]any{
  52. "pool_mode": true,
  53. "pool_mode_retry_count": json.Number("4"),
  54. },
  55. },
  56. expected: 4,
  57. },
  58. {
  59. name: "supports_string_value",
  60. account: &Account{
  61. Type: AccountTypeAPIKey,
  62. Platform: PlatformOpenAI,
  63. Credentials: map[string]any{
  64. "pool_mode": true,
  65. "pool_mode_retry_count": "2",
  66. },
  67. },
  68. expected: 2,
  69. },
  70. {
  71. name: "negative_value_is_clamped_to_zero",
  72. account: &Account{
  73. Type: AccountTypeAPIKey,
  74. Platform: PlatformOpenAI,
  75. Credentials: map[string]any{
  76. "pool_mode": true,
  77. "pool_mode_retry_count": -1,
  78. },
  79. },
  80. expected: 0,
  81. },
  82. {
  83. name: "oversized_value_is_clamped_to_max",
  84. account: &Account{
  85. Type: AccountTypeAPIKey,
  86. Platform: PlatformOpenAI,
  87. Credentials: map[string]any{
  88. "pool_mode": true,
  89. "pool_mode_retry_count": 99,
  90. },
  91. },
  92. expected: maxPoolModeRetryCount,
  93. },
  94. {
  95. name: "invalid_value_falls_back_to_default",
  96. account: &Account{
  97. Type: AccountTypeAPIKey,
  98. Platform: PlatformOpenAI,
  99. Credentials: map[string]any{
  100. "pool_mode": true,
  101. "pool_mode_retry_count": "oops",
  102. },
  103. },
  104. expected: defaultPoolModeRetryCount,
  105. },
  106. }
  107. for _, tt := range tests {
  108. t.Run(tt.name, func(t *testing.T) {
  109. require.Equal(t, tt.expected, tt.account.GetPoolModeRetryCount())
  110. })
  111. }
  112. }