cgroup_manager_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // +build linux
  2. /*
  3. Copyright 2016 The Kubernetes Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package cm
  15. import (
  16. "reflect"
  17. "testing"
  18. "k8s.io/api/core/v1"
  19. )
  20. func Test(t *testing.T) {
  21. tests := []struct {
  22. input map[string]string
  23. expected *map[v1.ResourceName]int64
  24. }{
  25. {
  26. input: map[string]string{"memory": ""},
  27. expected: nil,
  28. },
  29. {
  30. input: map[string]string{"memory": "a"},
  31. expected: nil,
  32. },
  33. {
  34. input: map[string]string{"memory": "a%"},
  35. expected: nil,
  36. },
  37. {
  38. input: map[string]string{"memory": "200%"},
  39. expected: nil,
  40. },
  41. {
  42. input: map[string]string{"memory": "0%"},
  43. expected: &map[v1.ResourceName]int64{
  44. v1.ResourceMemory: 0,
  45. },
  46. },
  47. {
  48. input: map[string]string{"memory": "100%"},
  49. expected: &map[v1.ResourceName]int64{
  50. v1.ResourceMemory: 100,
  51. },
  52. },
  53. {
  54. // need to change this when CPU is added as a supported resource
  55. input: map[string]string{"memory": "100%", "cpu": "50%"},
  56. expected: nil,
  57. },
  58. }
  59. for _, test := range tests {
  60. actual, err := ParseQOSReserved(test.input)
  61. if actual != nil && test.expected == nil {
  62. t.Errorf("Unexpected success, input: %v, expected: %v, actual: %v, err: %v", test.input, test.expected, actual, err)
  63. }
  64. if actual == nil && test.expected != nil {
  65. t.Errorf("Unexpected failure, input: %v, expected: %v, actual: %v, err: %v", test.input, test.expected, actual, err)
  66. }
  67. if (actual == nil && test.expected == nil) || reflect.DeepEqual(*actual, *test.expected) {
  68. continue
  69. }
  70. t.Errorf("Unexpected result, input: %v, expected: %v, actual: %v, err: %v", test.input, test.expected, actual, err)
  71. }
  72. }