fake.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // NewFake creates a fake sysctl implementation.
  23. func NewFake() *Fake {
  24. return &Fake{
  25. Settings: make(map[string]int),
  26. }
  27. }
  28. // GetSysctl returns the value for the specified sysctl setting.
  29. func (m *Fake) GetSysctl(sysctl string) (int, error) {
  30. v, found := m.Settings[sysctl]
  31. if !found {
  32. return -1, os.ErrNotExist
  33. }
  34. return v, nil
  35. }
  36. // SetSysctl modifies the specified sysctl flag to the new value.
  37. func (m *Fake) SetSysctl(sysctl string, newVal int) error {
  38. m.Settings[sysctl] = newVal
  39. return nil
  40. }
  41. var _ = sysctl.Interface(&Fake{})