policy_none_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package topologymanager
  14. import (
  15. "testing"
  16. )
  17. func TestPolicyNoneName(t *testing.T) {
  18. tcases := []struct {
  19. name string
  20. expected string
  21. }{
  22. {
  23. name: "New None Policy",
  24. expected: "none",
  25. },
  26. }
  27. for _, tc := range tcases {
  28. policy := NewNonePolicy()
  29. if policy.Name() != tc.expected {
  30. t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name())
  31. }
  32. }
  33. }
  34. func TestPolicyNoneCanAdmitPodResult(t *testing.T) {
  35. tcases := []struct {
  36. name string
  37. hint TopologyHint
  38. expected bool
  39. }{
  40. {
  41. name: "Preferred is set to false in topology hints",
  42. hint: TopologyHint{nil, false},
  43. expected: true,
  44. },
  45. {
  46. name: "Preferred is set to true in topology hints",
  47. hint: TopologyHint{nil, true},
  48. expected: true,
  49. },
  50. }
  51. for _, tc := range tcases {
  52. policy := NewNonePolicy()
  53. result := policy.(*nonePolicy).canAdmitPodResult(&tc.hint)
  54. if result != tc.expected {
  55. t.Errorf("Expected result to be %t, got %t", tc.expected, result)
  56. }
  57. }
  58. }
  59. func TestPolicyNoneMerge(t *testing.T) {
  60. tcases := []struct {
  61. name string
  62. providersHints []map[string][]TopologyHint
  63. expectedHint TopologyHint
  64. expectedAdmit bool
  65. }{
  66. {
  67. name: "merged empty providers hints",
  68. providersHints: []map[string][]TopologyHint{},
  69. expectedHint: TopologyHint{},
  70. expectedAdmit: true,
  71. },
  72. {
  73. name: "merge with a single provider with a single preferred resource",
  74. providersHints: []map[string][]TopologyHint{
  75. {
  76. "resource": {{NUMANodeAffinity: NewTestBitMask(0, 1), Preferred: true}},
  77. },
  78. },
  79. expectedHint: TopologyHint{},
  80. expectedAdmit: true,
  81. },
  82. {
  83. name: "merge with a single provider with a single non-preferred resource",
  84. providersHints: []map[string][]TopologyHint{
  85. {
  86. "resource": {{NUMANodeAffinity: NewTestBitMask(0, 1), Preferred: false}},
  87. },
  88. },
  89. expectedHint: TopologyHint{},
  90. expectedAdmit: true,
  91. },
  92. }
  93. for _, tc := range tcases {
  94. policy := NewNonePolicy()
  95. result, admit := policy.Merge(tc.providersHints)
  96. if !result.IsEqual(tc.expectedHint) || admit != tc.expectedAdmit {
  97. t.Errorf("Test Case: %s: Expected merge hint to be %v, got %v", tc.name, tc.expectedHint, result)
  98. }
  99. }
  100. }