costmodelenv_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package env
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. func TestIsCacheDisabled(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. want bool
  10. pre func()
  11. }{
  12. {
  13. name: "Ensure the default value is false",
  14. want: false,
  15. },
  16. {
  17. name: "Ensure the value is false when DISABLE_AGGREGATE_COST_MODEL_CACHE is set to false",
  18. want: false,
  19. pre: func() {
  20. os.Setenv("DISABLE_AGGREGATE_COST_MODEL_CACHE", "false")
  21. },
  22. },
  23. {
  24. name: "Ensure the value is true when DISABLE_AGGREGATE_COST_MODEL_CACHE is set to true",
  25. want: true,
  26. pre: func() {
  27. os.Setenv("DISABLE_AGGREGATE_COST_MODEL_CACHE", "true")
  28. },
  29. },
  30. }
  31. for _, tt := range tests {
  32. if tt.pre != nil {
  33. tt.pre()
  34. }
  35. t.Run(tt.name, func(t *testing.T) {
  36. if got := IsAggregateCostModelCacheDisabled(); got != tt.want {
  37. t.Errorf("IsAggregateCostModelCacheDisabled() = %v, want %v", got, tt.want)
  38. }
  39. })
  40. }
  41. }
  42. func TestGetExportCSVMaxDays(t *testing.T) {
  43. tests := []struct {
  44. name string
  45. want int
  46. pre func()
  47. }{
  48. {
  49. name: "Ensure the default value is 90d",
  50. want: 90,
  51. },
  52. {
  53. name: "Ensure the value is 30 when EXPORT_CSV_MAX_DAYS is set to 30",
  54. want: 30,
  55. pre: func() {
  56. os.Setenv("EXPORT_CSV_MAX_DAYS", "30")
  57. },
  58. },
  59. {
  60. name: "Ensure the value is 90 when EXPORT_CSV_MAX_DAYS is set to empty string",
  61. want: 90,
  62. pre: func() {
  63. os.Setenv("EXPORT_CSV_MAX_DAYS", "")
  64. },
  65. },
  66. {
  67. name: "Ensure the value is 90 when EXPORT_CSV_MAX_DAYS is set to invalid value",
  68. want: 90,
  69. pre: func() {
  70. os.Setenv("EXPORT_CSV_MAX_DAYS", "foo")
  71. },
  72. },
  73. }
  74. for _, tt := range tests {
  75. if tt.pre != nil {
  76. tt.pre()
  77. }
  78. t.Run(tt.name, func(t *testing.T) {
  79. if got := GetExportCSVMaxDays(); got != tt.want {
  80. t.Errorf("GetExportCSVMaxDays() = %v, want %v", got, tt.want)
  81. }
  82. })
  83. }
  84. }