2
0

module_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package public
  2. import (
  3. "testing"
  4. "github.com/opencost/opencost/core/pkg/model/shared"
  5. "github.com/opencost/opencost/core/pkg/pricing"
  6. "github.com/opencost/opencost/core/pkg/unit"
  7. )
  8. // TestPricingModuleConfig tests that the config struct is properly defined
  9. func TestPricingModuleConfig(t *testing.T) {
  10. config := PricingModuleConfig{
  11. Provider: shared.ProviderAWS,
  12. Currency: unit.USD,
  13. }
  14. if config.Provider != shared.ProviderAWS {
  15. t.Errorf("Provider = %v, want %v", config.Provider, shared.ProviderAWS)
  16. }
  17. if config.Currency != unit.USD {
  18. t.Errorf("Currency = %v, want %v", config.Currency, unit.USD)
  19. }
  20. }
  21. // TestProviderPricingStructure tests the nested map structure
  22. func TestProviderPricingStructure(t *testing.T) {
  23. providers := make(ProviderPricing)
  24. // Create a simple structure
  25. instanceMap := make(InstanceTypePricing)
  26. regionMap := make(RegionPricing)
  27. prices := &pricing.Prices{
  28. pricing.ResourceNode: pricing.Price{
  29. Unit: unit.Hour,
  30. Price: 0.0416,
  31. },
  32. }
  33. regionMap["us-east-1"] = prices
  34. instanceMap["t3.medium"] = &regionMap
  35. providers[shared.ProviderAWS] = &instanceMap
  36. // Verify structure
  37. if providers[shared.ProviderAWS] == nil {
  38. t.Fatal("AWS provider not found")
  39. }
  40. if (*providers[shared.ProviderAWS])["t3.medium"] == nil {
  41. t.Fatal("t3.medium instance type not found")
  42. }
  43. if (*(*providers[shared.ProviderAWS])["t3.medium"])["us-east-1"] == nil {
  44. t.Fatal("us-east-1 region not found")
  45. }
  46. }
  47. // Made with Bob