account_intercept_warmup_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //go:build unit
  2. package service
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestAccount_IsInterceptWarmupEnabled(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. credentials map[string]any
  11. expected bool
  12. }{
  13. {
  14. name: "nil credentials",
  15. credentials: nil,
  16. expected: false,
  17. },
  18. {
  19. name: "empty map",
  20. credentials: map[string]any{},
  21. expected: false,
  22. },
  23. {
  24. name: "field not present",
  25. credentials: map[string]any{"access_token": "tok"},
  26. expected: false,
  27. },
  28. {
  29. name: "field is true",
  30. credentials: map[string]any{"intercept_warmup_requests": true},
  31. expected: true,
  32. },
  33. {
  34. name: "field is false",
  35. credentials: map[string]any{"intercept_warmup_requests": false},
  36. expected: false,
  37. },
  38. {
  39. name: "field is string true",
  40. credentials: map[string]any{"intercept_warmup_requests": "true"},
  41. expected: false,
  42. },
  43. {
  44. name: "field is int 1",
  45. credentials: map[string]any{"intercept_warmup_requests": 1},
  46. expected: false,
  47. },
  48. {
  49. name: "field is nil",
  50. credentials: map[string]any{"intercept_warmup_requests": nil},
  51. expected: false,
  52. },
  53. }
  54. for _, tt := range tests {
  55. t.Run(tt.name, func(t *testing.T) {
  56. a := &Account{Credentials: tt.credentials}
  57. result := a.IsInterceptWarmupEnabled()
  58. require.Equal(t, tt.expected, result)
  59. })
  60. }
  61. }