server_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "k8s.io/kubernetes/pkg/kubelet"
  17. "k8s.io/kubernetes/pkg/util/config"
  18. )
  19. func TestValueOfAllocatableResources(t *testing.T) {
  20. testCases := []struct {
  21. kubeReserved string
  22. systemReserved string
  23. errorExpected bool
  24. name string
  25. }{
  26. {
  27. kubeReserved: "cpu=200m,memory=-150G",
  28. systemReserved: "cpu=200m,memory=150G",
  29. errorExpected: true,
  30. name: "negative quantity value",
  31. },
  32. {
  33. kubeReserved: "cpu=200m,memory=150GG",
  34. systemReserved: "cpu=200m,memory=150G",
  35. errorExpected: true,
  36. name: "invalid quantity unit",
  37. },
  38. {
  39. kubeReserved: "cpu=200m,memory=15G",
  40. systemReserved: "cpu=200m,memory=15Ki",
  41. errorExpected: false,
  42. name: "Valid resource quantity",
  43. },
  44. }
  45. for _, test := range testCases {
  46. kubeReservedCM := make(config.ConfigurationMap)
  47. systemReservedCM := make(config.ConfigurationMap)
  48. kubeReservedCM.Set(test.kubeReserved)
  49. systemReservedCM.Set(test.systemReserved)
  50. _, err := kubelet.ParseReservation(kubeReservedCM, systemReservedCM)
  51. if err != nil {
  52. t.Logf("%s: error returned: %v", test.name, err)
  53. }
  54. if test.errorExpected {
  55. if err == nil {
  56. t.Errorf("%s: error expected", test.name)
  57. }
  58. } else {
  59. if err != nil {
  60. t.Errorf("%s: unexpected error: %v", test.name, err)
  61. }
  62. }
  63. }
  64. }