cloudcost_test.go 780 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. }