aggregation_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package costmodel
  2. import (
  3. "testing"
  4. "github.com/opencost/opencost/core/pkg/opencost"
  5. )
  6. func TestParseAggregationProperties_Default(t *testing.T) {
  7. got, err := ParseAggregationProperties([]string{})
  8. expected := []string{
  9. opencost.AllocationClusterProp,
  10. opencost.AllocationNodeProp,
  11. opencost.AllocationNamespaceProp,
  12. opencost.AllocationPodProp,
  13. opencost.AllocationContainerProp,
  14. }
  15. if err != nil {
  16. t.Fatalf("TestParseAggregationPropertiesDefault: unexpected error: %s", err)
  17. }
  18. if len(expected) != len(got) {
  19. t.Fatalf("TestParseAggregationPropertiesDefault: expected length of %d, got: %d", len(expected), len(got))
  20. }
  21. for i := range got {
  22. if got[i] != expected[i] {
  23. t.Fatalf("TestParseAggregationPropertiesDefault: expected[i] should be %s, got[i]:%s", expected[i], got[i])
  24. }
  25. }
  26. }
  27. func TestParseAggregationProperties_All(t *testing.T) {
  28. got, err := ParseAggregationProperties([]string{"all"})
  29. if err != nil {
  30. t.Fatalf("TestParseAggregationPropertiesDefault: unexpected error: %s", err)
  31. }
  32. if len(got) != 0 {
  33. t.Fatalf("TestParseAggregationPropertiesDefault: expected length of 0, got: %d", len(got))
  34. }
  35. }