window_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package filter_test
  2. // import (
  3. // "github.com/opencost/opencost/pkg/kubecost"
  4. // "testing"
  5. // "time"
  6. // )
  7. // type windowedImpl struct {
  8. // kubecost.Window
  9. // }
  10. // func (w *windowedImpl) GetWindow() kubecost.Window {
  11. // return w.Window
  12. // }
  13. // func newWindowedImpl(start, end *time.Time) *windowedImpl {
  14. // return &windowedImpl{kubecost.NewWindow(start, end)}
  15. // }
  16. // func Test_WindowContains_Matches(t *testing.T) {
  17. // noon := time.Date(2022, 9, 29, 12, 0, 0, 0, time.UTC)
  18. // one := noon.Add(time.Hour)
  19. // two := one.Add(time.Hour)
  20. // three := two.Add(time.Hour)
  21. // cases := map[string]struct {
  22. // windowed *windowedImpl
  23. // filter Filter[*windowedImpl]
  24. // expected bool
  25. // }{
  26. // "fully contains": {
  27. // windowed: newWindowedImpl(&one, &two),
  28. // filter: WindowCondition[*windowedImpl]{
  29. // Window: kubecost.NewWindow(&noon, &three),
  30. // Op: WindowContains,
  31. // },
  32. // expected: true,
  33. // },
  34. // "window matches": {
  35. // windowed: newWindowedImpl(&one, &two),
  36. // filter: WindowCondition[*windowedImpl]{
  37. // Window: kubecost.NewWindow(&one, &two),
  38. // Op: WindowContains,
  39. // },
  40. // expected: true,
  41. // },
  42. // "contains start": {
  43. // windowed: newWindowedImpl(&one, &three),
  44. // filter: WindowCondition[*windowedImpl]{
  45. // Window: kubecost.NewWindow(&noon, &two),
  46. // Op: WindowContains,
  47. // },
  48. // expected: false,
  49. // },
  50. // "contains end": {
  51. // windowed: newWindowedImpl(&noon, &two),
  52. // filter: WindowCondition[*windowedImpl]{
  53. // Window: kubecost.NewWindow(&one, &three),
  54. // Op: WindowContains,
  55. // },
  56. // expected: false,
  57. // },
  58. // "window start = filter end": {
  59. // windowed: newWindowedImpl(&one, &two),
  60. // filter: WindowCondition[*windowedImpl]{
  61. // Window: kubecost.NewWindow(&noon, &one),
  62. // Op: WindowContains,
  63. // },
  64. // expected: false,
  65. // },
  66. // "window end = filter start": {
  67. // windowed: newWindowedImpl(&noon, &one),
  68. // filter: WindowCondition[*windowedImpl]{
  69. // Window: kubecost.NewWindow(&one, &two),
  70. // Op: WindowContains,
  71. // },
  72. // expected: false,
  73. // },
  74. // "window before": {
  75. // windowed: newWindowedImpl(&noon, &one),
  76. // filter: WindowCondition[*windowedImpl]{
  77. // Window: kubecost.NewWindow(&two, &three),
  78. // Op: WindowContains,
  79. // },
  80. // expected: false,
  81. // },
  82. // "window after": {
  83. // windowed: newWindowedImpl(&two, &three),
  84. // filter: WindowCondition[*windowedImpl]{
  85. // Window: kubecost.NewWindow(&noon, &one),
  86. // Op: WindowContains,
  87. // },
  88. // expected: false,
  89. // },
  90. // }
  91. // for name, c := range cases {
  92. // result := c.filter.Matches(c.windowed)
  93. // if result != c.expected {
  94. // t.Errorf("%s: expected %t, got %t", name, c.expected, result)
  95. // }
  96. // }
  97. // }