github.com/go-kivik/kivik/v4@v4.3.2/x/fsdb/filesystem/mock.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 package filesystem 14 15 import "os" 16 17 // MockFS allows mocking a filesystem. 18 type MockFS struct { 19 MkdirFunc func(string, os.FileMode) error 20 MkdirAllFunc func(string, os.FileMode) error 21 CreateFunc func(string) (File, error) 22 OpenFunc func(string) (File, error) 23 StatFunc func(string) (os.FileInfo, error) 24 TempFileFunc func(string, string) (File, error) 25 RenameFunc func(string, string) error 26 RemoveFunc func(string) error 27 LinkFunc func(string, string) error 28 } 29 30 var _ Filesystem = &MockFS{} 31 32 // Mkdir calls fs.MkdirFunc 33 func (fs *MockFS) Mkdir(name string, perm os.FileMode) error { 34 return fs.MkdirFunc(name, perm) 35 } 36 37 // MkdirAll calls fs.MkdirAllFunc 38 func (fs *MockFS) MkdirAll(path string, perm os.FileMode) error { 39 return fs.MkdirAllFunc(path, perm) 40 } 41 42 // Open calls fs.OpenFunc 43 func (fs *MockFS) Open(name string) (File, error) { 44 return fs.OpenFunc(name) 45 } 46 47 // Create calls fs.CreateFunc 48 func (fs *MockFS) Create(name string) (File, error) { 49 return fs.CreateFunc(name) 50 } 51 52 // Stat calls fs.StatFunc 53 func (fs *MockFS) Stat(name string) (os.FileInfo, error) { 54 return fs.StatFunc(name) 55 } 56 57 // TempFile calls fs.TempFileFunc 58 func (fs *MockFS) TempFile(dir, pattern string) (File, error) { 59 return fs.TempFileFunc(dir, pattern) 60 } 61 62 // Rename calls fs.RenameFunc 63 func (fs *MockFS) Rename(oldpath, newpath string) error { 64 return fs.RenameFunc(oldpath, newpath) 65 } 66 67 // Remove calls fs.RemoveFunc 68 func (fs *MockFS) Remove(name string) error { 69 return fs.RemoveFunc(name) 70 } 71 72 // Link calls fs.LinkFunc 73 func (fs *MockFS) Link(oldname, newname string) error { 74 return fs.LinkFunc(oldname, newname) 75 }