Micro-service for file storage and processing written in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.0 KiB

  1. package storage
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/spf13/afero"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestFileSystemStorageProvider(t *testing.T) {
  9. t.Run("storeRaw method stores files in filesystem", func(t *testing.T) {
  10. fileSystem := afero.NewMemMapFs()
  11. dummyData := []byte{0x13, 0x37}
  12. provider := FileSystemStorageProvider{
  13. fileSystem: fileSystem,
  14. basePath: "/tmp/foo/bar",
  15. }
  16. provider.storeRaw("test", "test.bin", dummyData)
  17. exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
  18. assert.True(t, exists)
  19. })
  20. t.Run("storeExisting method stores files in filesystem", func(t *testing.T) {
  21. fileSystem := afero.NewMemMapFs()
  22. afero.WriteFile(fileSystem, "/tmp/existing.bin", []byte{0x13, 0x37}, os.ModePerm)
  23. provider := FileSystemStorageProvider{
  24. fileSystem: fileSystem,
  25. basePath: "/tmp/foo/bar",
  26. }
  27. provider.storeExisting("test", "test.bin", "/tmp/existing.bin")
  28. exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
  29. assert.True(t, exists)
  30. })
  31. }