github.com/chenbh/concourse/v6@v6.4.2/worker/runtime/file_store_test.go (about) 1 package runtime_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 "github.com/chenbh/concourse/v6/worker/runtime" 9 "github.com/stretchr/testify/require" 10 "github.com/stretchr/testify/suite" 11 ) 12 13 type FileStoreSuite struct { 14 suite.Suite 15 *require.Assertions 16 17 rootfs string 18 store runtime.FileStore 19 } 20 21 func (s *FileStoreSuite) SetupTest() { 22 var err error 23 24 s.rootfs, err = ioutil.TempDir("", "bcknd-filestore") 25 s.NoError(err) 26 27 s.store = runtime.NewFileStore(s.rootfs) 28 } 29 30 func (s *FileStoreSuite) TearDownTest() { 31 os.RemoveAll(s.rootfs) 32 } 33 34 func (s *FileStoreSuite) TestCreateFile() { 35 fpath, err := s.store.Create("name", []byte("hey")) 36 s.NoError(err) 37 38 content, err := ioutil.ReadFile(fpath) 39 s.NoError(err) 40 s.Equal("hey", string(content)) 41 } 42 43 func (s *FileStoreSuite) TestCreateFileInDir() { 44 fpath, err := s.store.Create("dir/name", []byte("hey")) 45 s.NoError(err) 46 47 content, err := ioutil.ReadFile(fpath) 48 s.NoError(err) 49 s.Equal("hey", string(content)) 50 } 51 52 func (s *FileStoreSuite) TestDeleteFile() { 53 fpath, err := s.store.Create("dir/name", []byte("hey")) 54 s.NoError(err) 55 56 err = s.store.Delete("dir/name") 57 s.NoError(err) 58 59 _, err = os.Stat(fpath) 60 s.True(os.IsNotExist(err)) 61 } 62 63 func (s *FileStoreSuite) TestDeleteDir() { 64 fpath, err := s.store.Create("dir/name", []byte("hey")) 65 s.NoError(err) 66 67 err = s.store.Delete("dir") 68 s.NoError(err) 69 70 _, err = os.Stat(filepath.Dir(fpath)) 71 s.True(os.IsNotExist(err)) 72 }