github.com/3JoB/vfs@v1.0.0/example_dummy_test.go (about) 1 package vfs_test 2 3 import ( 4 "errors" 5 "fmt" 6 "os" 7 8 "github.com/3JoB/vfs" 9 ) 10 11 type myFS struct { 12 vfs.Filesystem // Embed the Filesystem interface and fill it with vfs.Dummy on creation 13 } 14 15 func MyFS() *myFS { 16 return &myFS{ 17 Filesystem: vfs.Dummy(errors.New("Not implemented yet!")), 18 } 19 } 20 21 func (fs myFS) Mkdir(name string, perm os.FileMode) error { 22 // Create a directory 23 // ... 24 return nil 25 } 26 27 func ExampleDummyFS() { 28 // Simply bootstrap your filesystem 29 var fs vfs.Filesystem = MyFS() 30 31 // Your mkdir implementation 32 fs.Mkdir("/tmp", 0777) 33 34 // All necessary methods like OpenFile (therefor Create) are stubbed 35 // and return the dummys error 36 _, err := vfs.Create(fs, "/tmp/vfs/example.txt") 37 if err != nil { 38 fmt.Print("Error will be: Not implemented yet!\n") 39 } 40 }