fake.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2015 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 testing
  14. import (
  15. "os"
  16. "k8s.io/kubernetes/pkg/util/sysctl"
  17. )
  18. // fake is a map-backed implementation of sysctl.Interface, for testing/mocking
  19. type fake struct {
  20. Settings map[string]int
  21. }
  22. func NewFake() *fake {
  23. return &fake{
  24. Settings: make(map[string]int),
  25. }
  26. }
  27. // GetSysctl returns the value for the specified sysctl setting
  28. func (m *fake) GetSysctl(sysctl string) (int, error) {
  29. v, found := m.Settings[sysctl]
  30. if !found {
  31. return -1, os.ErrNotExist
  32. }
  33. return v, nil
  34. }
  35. // SetSysctl modifies the specified sysctl flag to the new value
  36. func (m *fake) SetSysctl(sysctl string, newVal int) error {
  37. m.Settings[sysctl] = newVal
  38. return nil
  39. }
  40. var _ = sysctl.Interface(&fake{})