server_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright 2016 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 app
  14. import (
  15. "testing"
  16. )
  17. func TestValueOfAllocatableResources(t *testing.T) {
  18. testCases := []struct {
  19. kubeReserved map[string]string
  20. systemReserved map[string]string
  21. errorExpected bool
  22. name string
  23. }{
  24. {
  25. kubeReserved: map[string]string{"cpu": "200m", "memory": "-150G", "ephemeral-storage": "10Gi"},
  26. systemReserved: map[string]string{"cpu": "200m", "memory": "15Ki"},
  27. errorExpected: true,
  28. name: "negative quantity value",
  29. },
  30. {
  31. kubeReserved: map[string]string{"cpu": "200m", "memory": "150Gi", "ephemeral-storage": "10Gi"},
  32. systemReserved: map[string]string{"cpu": "200m", "memory": "15Ky"},
  33. errorExpected: true,
  34. name: "invalid quantity unit",
  35. },
  36. {
  37. kubeReserved: map[string]string{"cpu": "200m", "memory": "15G", "ephemeral-storage": "10Gi"},
  38. systemReserved: map[string]string{"cpu": "200m", "memory": "15Ki"},
  39. errorExpected: false,
  40. name: "Valid resource quantity",
  41. },
  42. }
  43. for _, test := range testCases {
  44. _, err1 := parseResourceList(test.kubeReserved)
  45. _, err2 := parseResourceList(test.systemReserved)
  46. if test.errorExpected {
  47. if err1 == nil && err2 == nil {
  48. t.Errorf("%s: error expected", test.name)
  49. }
  50. } else {
  51. if err1 != nil || err2 != nil {
  52. t.Errorf("%s: unexpected error: %v, %v", test.name, err1, err2)
  53. }
  54. }
  55. }
  56. }