cloudcost_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package env
  2. import (
  3. "testing"
  4. "github.com/opencost/opencost/core/pkg/env"
  5. )
  6. func TestGetCloudCostConfigPath(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. want string
  10. pre func()
  11. }{
  12. {
  13. name: "Ensure the default value is 'cloud-integration.json'",
  14. want: "/var/configs/cloud-integration.json",
  15. },
  16. {
  17. name: "Ensure the value is 'cloud-integration.json' when CLOUD_COST_CONFIG_PATH is set to ''",
  18. want: "/test/cloud-integration.json",
  19. pre: func() {
  20. env.Set(env.ConfigPathEnvVar, "/test")
  21. },
  22. },
  23. }
  24. for _, tt := range tests {
  25. if tt.pre != nil {
  26. tt.pre()
  27. }
  28. t.Run(tt.name, func(t *testing.T) {
  29. if got := GetCloudCostConfigPath(); got != tt.want {
  30. t.Errorf("GetCloudCostConfigPath() = %v, want %v", got, tt.want)
  31. }
  32. })
  33. }
  34. }
  35. func TestGetCloudCostPvRetention(t *testing.T) {
  36. tests := []struct {
  37. name string
  38. want int
  39. pre func()
  40. }{
  41. {
  42. name: "Ensure the default value is '2'",
  43. want: 2,
  44. },
  45. {
  46. name: "Ensure the value is 7 when CLOUD_COST_PVC_RETENTION is set to '7'",
  47. want: 7,
  48. pre: func() {
  49. env.Set(CloudCostPvRetentionEnvVar, "7")
  50. },
  51. },
  52. }
  53. for _, tt := range tests {
  54. if tt.pre != nil {
  55. tt.pre()
  56. }
  57. t.Run(tt.name, func(t *testing.T) {
  58. if got := GetCloudCostPvRetention(); got != tt.want {
  59. t.Errorf("GetCloudCostPvRetention() = %v, want %v", got, tt.want)
  60. }
  61. })
  62. }
  63. }