Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package test
  2. import (
  3. "bytes"
  4. "os"
  5. "path"
  6. "path/filepath"
  7. "gopkg.in/src-d/go-billy.v4"
  8. )
  9. type BasicMock struct {
  10. CreateArgs []string
  11. OpenArgs []string
  12. OpenFileArgs [][3]interface{}
  13. StatArgs []string
  14. RenameArgs [][2]string
  15. RemoveArgs []string
  16. JoinArgs [][]string
  17. }
  18. func (fs *BasicMock) Create(filename string) (billy.File, error) {
  19. fs.CreateArgs = append(fs.CreateArgs, filename)
  20. return &FileMock{name: filename}, nil
  21. }
  22. func (fs *BasicMock) Open(filename string) (billy.File, error) {
  23. fs.OpenArgs = append(fs.OpenArgs, filename)
  24. return &FileMock{name: filename}, nil
  25. }
  26. func (fs *BasicMock) OpenFile(filename string, flag int, mode os.FileMode) (billy.File, error) {
  27. fs.OpenFileArgs = append(fs.OpenFileArgs, [3]interface{}{filename, flag, mode})
  28. return &FileMock{name: filename}, nil
  29. }
  30. func (fs *BasicMock) Stat(filename string) (os.FileInfo, error) {
  31. fs.StatArgs = append(fs.StatArgs, filename)
  32. return nil, nil
  33. }
  34. func (fs *BasicMock) Rename(target, link string) error {
  35. fs.RenameArgs = append(fs.RenameArgs, [2]string{target, link})
  36. return nil
  37. }
  38. func (fs *BasicMock) Remove(filename string) error {
  39. fs.RemoveArgs = append(fs.RemoveArgs, filename)
  40. return nil
  41. }
  42. func (fs *BasicMock) Join(elem ...string) string {
  43. fs.JoinArgs = append(fs.JoinArgs, elem)
  44. return path.Join(elem...)
  45. }
  46. type TempFileMock struct {
  47. BasicMock
  48. TempFileArgs [][2]string
  49. }
  50. func (fs *TempFileMock) TempFile(dir, prefix string) (billy.File, error) {
  51. fs.TempFileArgs = append(fs.TempFileArgs, [2]string{dir, prefix})
  52. return &FileMock{name: "/tmp/hardcoded/mock/temp"}, nil
  53. }
  54. type DirMock struct {
  55. BasicMock
  56. ReadDirArgs []string
  57. MkdirAllArgs [][2]interface{}
  58. }
  59. func (fs *DirMock) ReadDir(path string) ([]os.FileInfo, error) {
  60. fs.ReadDirArgs = append(fs.ReadDirArgs, path)
  61. return nil, nil
  62. }
  63. func (fs *DirMock) MkdirAll(filename string, perm os.FileMode) error {
  64. fs.MkdirAllArgs = append(fs.MkdirAllArgs, [2]interface{}{filename, perm})
  65. return nil
  66. }
  67. type SymlinkMock struct {
  68. BasicMock
  69. LstatArgs []string
  70. SymlinkArgs [][2]string
  71. ReadlinkArgs []string
  72. }
  73. func (fs *SymlinkMock) Lstat(filename string) (os.FileInfo, error) {
  74. fs.LstatArgs = append(fs.LstatArgs, filename)
  75. return nil, nil
  76. }
  77. func (fs *SymlinkMock) Symlink(target, link string) error {
  78. fs.SymlinkArgs = append(fs.SymlinkArgs, [2]string{target, link})
  79. return nil
  80. }
  81. func (fs *SymlinkMock) Readlink(link string) (string, error) {
  82. fs.ReadlinkArgs = append(fs.ReadlinkArgs, link)
  83. return filepath.FromSlash(link), nil
  84. }
  85. type FileMock struct {
  86. name string
  87. bytes.Buffer
  88. }
  89. func (f *FileMock) Name() string {
  90. return f.name
  91. }
  92. func (*FileMock) ReadAt(b []byte, off int64) (int, error) {
  93. return 0, nil
  94. }
  95. func (*FileMock) Seek(offset int64, whence int) (int64, error) {
  96. return 0, nil
  97. }
  98. func (*FileMock) Close() error {
  99. return nil
  100. }
  101. func (*FileMock) Lock() error {
  102. return nil
  103. }
  104. func (*FileMock) Unlock() error {
  105. return nil
  106. }
  107. func (*FileMock) Truncate(size int64) error {
  108. return nil
  109. }
  110. type OnlyReadCapFs struct {
  111. BasicMock
  112. }
  113. func (o *OnlyReadCapFs) Capabilities() billy.Capability {
  114. return billy.ReadCapability
  115. }
  116. type NoLockCapFs struct {
  117. BasicMock
  118. }
  119. func (o *NoLockCapFs) Capabilities() billy.Capability {
  120. return billy.WriteCapability |
  121. billy.ReadCapability |
  122. billy.ReadAndWriteCapability |
  123. billy.SeekCapability |
  124. billy.TruncateCapability
  125. }