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.

51 lines
1.4 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. dummyData := []byte{0x13, 0x37}
  10. t.Run("storeRaw method stores files in filesystem", func(t *testing.T) {
  11. fileSystem := afero.NewMemMapFs()
  12. provider := FileSystemStorageProvider{
  13. fileSystem: fileSystem,
  14. basePath: "/tmp/foo/bar",
  15. }
  16. finalPath := provider.storeRaw("test", "test.bin", dummyData)
  17. assert.Equal(t, "/tmp/foo/bar/test/test.bin", finalPath)
  18. exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
  19. assert.True(t, exists)
  20. content, _ := afero.ReadFile(fileSystem, "/tmp/foo/bar/test/test.bin")
  21. assert.Equal(t, dummyData, content)
  22. })
  23. t.Run("storeExisting method stores files in filesystem", func(t *testing.T) {
  24. fileSystem := afero.NewMemMapFs()
  25. afero.WriteFile(fileSystem, "/tmp/existing.bin", dummyData, os.ModePerm)
  26. provider := FileSystemStorageProvider{
  27. fileSystem: fileSystem,
  28. basePath: "/tmp/foo/bar",
  29. }
  30. finalPath := provider.storeExisting("test", "test.bin", "/tmp/existing.bin")
  31. assert.Equal(t, "/tmp/foo/bar/test/test.bin", finalPath)
  32. exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
  33. assert.True(t, exists)
  34. content, _ := afero.ReadFile(fileSystem, "/tmp/foo/bar/test/test.bin")
  35. assert.Equal(t, dummyData, content)
  36. })
  37. }