cluster_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package costmodel
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func Test_filterOutLocalPVs(t *testing.T) {
  7. testCases := []struct {
  8. name string
  9. input map[DiskIdentifier]*Disk
  10. expected map[DiskIdentifier]*Disk
  11. }{
  12. {
  13. name: "Filter out local PVs",
  14. input: map[DiskIdentifier]*Disk{
  15. {Cluster: "cluster1", Name: "pv1"}: {Name: "pv1"},
  16. {Cluster: "cluster1", Name: "local-pv-123"}: {Name: "local-pv-123"},
  17. {Cluster: "cluster2", Name: "pv2"}: {Name: "pv2"},
  18. {Cluster: "cluster2", Name: "local-pv-456"}: {Name: "local-pv-456"},
  19. {Cluster: "cluster3", Name: "not-local-pv-789"}: {Name: "not-local-pv-789"},
  20. },
  21. expected: map[DiskIdentifier]*Disk{
  22. {Cluster: "cluster1", Name: "pv1"}: {Name: "pv1"},
  23. {Cluster: "cluster2", Name: "pv2"}: {Name: "pv2"},
  24. {Cluster: "cluster3", Name: "not-local-pv-789"}: {Name: "not-local-pv-789"},
  25. },
  26. },
  27. {
  28. name: "No local PVs to filter",
  29. input: map[DiskIdentifier]*Disk{
  30. {Cluster: "cluster1", Name: "pv1"}: {Name: "pv1"},
  31. {Cluster: "cluster2", Name: "pv2"}: {Name: "pv2"},
  32. },
  33. expected: map[DiskIdentifier]*Disk{
  34. {Cluster: "cluster1", Name: "pv1"}: {Name: "pv1"},
  35. {Cluster: "cluster2", Name: "pv2"}: {Name: "pv2"},
  36. },
  37. },
  38. {
  39. name: "Empty input",
  40. input: map[DiskIdentifier]*Disk{},
  41. expected: map[DiskIdentifier]*Disk{},
  42. },
  43. }
  44. for _, tc := range testCases {
  45. t.Run(tc.name, func(t *testing.T) {
  46. result := filterOutLocalPVs(tc.input)
  47. assert.Equal(t, tc.expected, result)
  48. })
  49. }
  50. }