costmodel_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package env
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. func TestGetExportCSVMaxDays(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. want int
  10. pre func()
  11. }{
  12. {
  13. name: "Ensure the default value is 90d",
  14. want: 90,
  15. },
  16. {
  17. name: "Ensure the value is 30 when EXPORT_CSV_MAX_DAYS is set to 30",
  18. want: 30,
  19. pre: func() {
  20. os.Setenv("EXPORT_CSV_MAX_DAYS", "30")
  21. },
  22. },
  23. {
  24. name: "Ensure the value is 90 when EXPORT_CSV_MAX_DAYS is set to empty string",
  25. want: 90,
  26. pre: func() {
  27. os.Setenv("EXPORT_CSV_MAX_DAYS", "")
  28. },
  29. },
  30. {
  31. name: "Ensure the value is 90 when EXPORT_CSV_MAX_DAYS is set to invalid value",
  32. want: 90,
  33. pre: func() {
  34. os.Setenv("EXPORT_CSV_MAX_DAYS", "foo")
  35. },
  36. },
  37. }
  38. for _, tt := range tests {
  39. if tt.pre != nil {
  40. tt.pre()
  41. }
  42. t.Run(tt.name, func(t *testing.T) {
  43. if got := GetExportCSVMaxDays(); got != tt.want {
  44. t.Errorf("GetExportCSVMaxDays() = %v, want %v", got, tt.want)
  45. }
  46. })
  47. }
  48. }
  49. func TestGetKubernetesEnabled(t *testing.T) {
  50. tests := []struct {
  51. name string
  52. want bool
  53. pre func()
  54. }{
  55. {
  56. name: "Ensure the default value is false",
  57. want: false,
  58. },
  59. {
  60. name: "Ensure the value is true when KUBERNETES_PORT has a value",
  61. want: true,
  62. pre: func() {
  63. os.Setenv("KUBERNETES_PORT", "tcp://10.43.0.1:443")
  64. },
  65. },
  66. }
  67. for _, tt := range tests {
  68. if tt.pre != nil {
  69. tt.pre()
  70. }
  71. t.Run(tt.name, func(t *testing.T) {
  72. if got := IsKubernetesEnabled(); got != tt.want {
  73. t.Errorf("IsKubernetesEnabled() = %v, want %v", got, tt.want)
  74. }
  75. })
  76. }
  77. }
  78. func TestIsMCPServerEnabled_DefaultFalse(t *testing.T) {
  79. old, hadOld := os.LookupEnv("MCP_SERVER_ENABLED")
  80. os.Unsetenv("MCP_SERVER_ENABLED")
  81. t.Cleanup(func() {
  82. if hadOld {
  83. os.Setenv("MCP_SERVER_ENABLED", old)
  84. } else {
  85. os.Unsetenv("MCP_SERVER_ENABLED")
  86. }
  87. })
  88. if got := IsMCPServerEnabled(); got {
  89. t.Fatalf("expected false when MCP_SERVER_ENABLED is unset, got %v", got)
  90. }
  91. }
  92. func TestIsMCPServerEnabled_True(t *testing.T) {
  93. t.Setenv("MCP_SERVER_ENABLED", "true")
  94. if got := IsMCPServerEnabled(); !got {
  95. t.Fatalf("expected true when env var set to true, got %v", got)
  96. }
  97. }