filesystem.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright 2017 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 filesystem
  14. import (
  15. "os"
  16. "path/filepath"
  17. "time"
  18. )
  19. // Filesystem is an interface that we can use to mock various filesystem operations
  20. type Filesystem interface {
  21. // from "os"
  22. Stat(name string) (os.FileInfo, error)
  23. Create(name string) (File, error)
  24. Rename(oldpath, newpath string) error
  25. MkdirAll(path string, perm os.FileMode) error
  26. Chtimes(name string, atime time.Time, mtime time.Time) error
  27. RemoveAll(path string) error
  28. Remove(name string) error
  29. // from "io/ioutil"
  30. ReadFile(filename string) ([]byte, error)
  31. TempDir(dir, prefix string) (string, error)
  32. TempFile(dir, prefix string) (File, error)
  33. ReadDir(dirname string) ([]os.FileInfo, error)
  34. Walk(root string, walkFn filepath.WalkFunc) error
  35. }
  36. // File is an interface that we can use to mock various filesystem operations typically
  37. // accessed through the File object from the "os" package
  38. type File interface {
  39. // for now, the only os.File methods used are those below, add more as necessary
  40. Name() string
  41. Write(b []byte) (n int, err error)
  42. Sync() error
  43. Close() error
  44. }