cgroup_validator_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 system
  14. import (
  15. "testing"
  16. "github.com/stretchr/testify/assert"
  17. )
  18. func TestValidateCgroupSubsystem(t *testing.T) {
  19. v := &CgroupsValidator{
  20. Reporter: DefaultReporter,
  21. }
  22. cgroupSpec := []string{"system1", "system2"}
  23. for desc, test := range map[string]struct {
  24. subsystems []string
  25. err bool
  26. }{
  27. "missing cgroup subsystem should report error": {
  28. subsystems: []string{"system1"},
  29. err: true,
  30. },
  31. "extra cgroup subsystems should not report error": {
  32. subsystems: []string{"system1", "system2", "system3"},
  33. err: false,
  34. },
  35. "subsystems the same with spec should not report error": {
  36. subsystems: []string{"system1", "system2"},
  37. err: false,
  38. },
  39. } {
  40. t.Run(desc, func(t *testing.T) {
  41. err := v.validateCgroupSubsystems(cgroupSpec, test.subsystems)
  42. if !test.err {
  43. assert.Nil(t, err, "%q: Expect error not to occur with cgroup", desc)
  44. } else {
  45. assert.NotNil(t, err, "%q: Expect error to occur with docker info", desc)
  46. }
  47. })
  48. }
  49. }