policy_strict_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 TestCanAdmitPodResult(t *testing.T) {
  18. tcases := []struct {
  19. name string
  20. admit bool
  21. expected bool
  22. }{
  23. {
  24. name: "Affinity is set to false in topology hints",
  25. admit: false,
  26. expected: false,
  27. },
  28. {
  29. name: "Affinity is set to true in topology hints",
  30. admit: true,
  31. expected: true,
  32. },
  33. }
  34. for _, tc := range tcases {
  35. policy := NewStrictPolicy()
  36. admit := tc.admit
  37. result := policy.CanAdmitPodResult(admit)
  38. if result.Admit != tc.expected {
  39. t.Errorf("Expected Admit field in result to be %t, got %t", tc.expected, result.Admit)
  40. }
  41. if tc.expected == false {
  42. if len(result.Reason) == 0 {
  43. t.Errorf("Expected Reason field to be not empty")
  44. }
  45. if len(result.Message) == 0 {
  46. t.Errorf("Expected Message field to be not empty")
  47. }
  48. }
  49. }
  50. }