tolerations_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2017 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 tolerations
  14. import (
  15. api "k8s.io/kubernetes/pkg/apis/core"
  16. "testing"
  17. )
  18. func TestVerifyAgainstWhitelist(t *testing.T) {
  19. tests := []struct {
  20. input []api.Toleration
  21. whitelist []api.Toleration
  22. testName string
  23. testStatus bool
  24. }{
  25. {
  26. input: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoSchedule"}},
  27. whitelist: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoSchedule"}},
  28. testName: "equal input and whitelist",
  29. testStatus: true,
  30. },
  31. {
  32. input: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoSchedule"}},
  33. whitelist: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoExecute"}},
  34. testName: "input does not exist in whitelist",
  35. testStatus: false,
  36. },
  37. }
  38. for _, c := range tests {
  39. status := VerifyAgainstWhitelist(c.input, c.whitelist)
  40. if status != c.testStatus {
  41. t.Errorf("Test: %s, expected %v", c.testName, status)
  42. }
  43. }
  44. }
  45. func TestIsConflict(t *testing.T) {
  46. tests := []struct {
  47. input1 []api.Toleration
  48. input2 []api.Toleration
  49. testName string
  50. testStatus bool
  51. }{
  52. {
  53. input1: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoSchedule"}},
  54. input2: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoSchedule"}},
  55. testName: "equal inputs",
  56. testStatus: true,
  57. },
  58. {
  59. input1: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "foo", Effect: "NoExecute"}},
  60. input2: []api.Toleration{{Key: "foo", Operator: "Equal", Value: "bar", Effect: "NoExecute"}},
  61. testName: "mismatch values in inputs",
  62. testStatus: false,
  63. },
  64. }
  65. for _, c := range tests {
  66. status := IsConflict(c.input1, c.input2)
  67. if status == c.testStatus {
  68. t.Errorf("Test: %s, expected %v", c.testName, status)
  69. }
  70. }
  71. }