cgroupdriver_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2018 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 util
  14. import (
  15. "testing"
  16. )
  17. func TestGetCgroupDriverDocker(t *testing.T) {
  18. testCases := []struct {
  19. name string
  20. driver string
  21. expectedError bool
  22. }{
  23. {
  24. name: "valid: value is 'cgroupfs'",
  25. driver: `cgroupfs`,
  26. expectedError: false,
  27. },
  28. {
  29. name: "valid: value is 'systemd'",
  30. driver: `systemd`,
  31. expectedError: false,
  32. },
  33. {
  34. name: "invalid: empty 'Cgroup Driver' value",
  35. driver: ``,
  36. expectedError: true,
  37. },
  38. {
  39. name: "invalid: unknown 'Cgroup Driver' value",
  40. driver: `invalid-value`,
  41. expectedError: true,
  42. },
  43. }
  44. for _, tc := range testCases {
  45. t.Run(tc.name, func(t *testing.T) {
  46. result := tc.driver != CgroupDriverCgroupfs && tc.driver != CgroupDriverSystemd
  47. if result != tc.expectedError {
  48. t.Fatalf("expected error: %v, saw: %v", tc.expectedError, result)
  49. }
  50. })
  51. }
  52. }