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.

49 lines
1.2 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. provider.storeRaw("test", "test.bin", dummyData)
  17. exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
  18. assert.True(t, exists)
  19. content, _ := afero.ReadFile(fileSystem, "/tmp/foo/bar/test/test.bin")
  20. assert.Equal(t, dummyData, content)
  21. })
  22. t.Run("storeExisting method stores files in filesystem", func(t *testing.T) {
  23. fileSystem := afero.NewMemMapFs()
  24. afero.WriteFile(fileSystem, "/tmp/existing.bin", dummyData, os.ModePerm)
  25. provider := FileSystemStorageProvider{
  26. fileSystem: fileSystem,
  27. basePath: "/tmp/foo/bar",
  28. }
  29. provider.storeExisting("test", "test.bin", "/tmp/existing.bin")
  30. exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
  31. assert.True(t, exists)
  32. content, _ := afero.ReadFile(fileSystem, "/tmp/foo/bar/test/test.bin")
  33. assert.Equal(t, dummyData, content)
  34. })
  35. }