forked from FabianVowie/Lithium
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.
54 lines
1.4 KiB
54 lines
1.4 KiB
package storage
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFileSystemStorageProvider(t *testing.T) {
|
|
dummyData := []byte{0x13, 0x37}
|
|
|
|
t.Run("storeRaw method stores files in filesystem", func(t *testing.T) {
|
|
fileSystem := afero.NewMemMapFs()
|
|
|
|
provider := FileSystemStorageProvider{
|
|
fileSystem: fileSystem,
|
|
basePath: "/tmp/foo/bar",
|
|
}
|
|
|
|
finalPath, err := provider.StoreRaw("test", "test.bin", dummyData)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "/tmp/foo/bar/test/test.bin", finalPath)
|
|
|
|
exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
|
|
assert.True(t, exists)
|
|
|
|
content, _ := afero.ReadFile(fileSystem, "/tmp/foo/bar/test/test.bin")
|
|
assert.Equal(t, dummyData, content)
|
|
})
|
|
|
|
t.Run("storeExisting method stores files in filesystem", func(t *testing.T) {
|
|
fileSystem := afero.NewMemMapFs()
|
|
|
|
err := os.WriteFile("/tmp/existing.bin", dummyData, os.ModePerm)
|
|
assert.Nil(t, err)
|
|
|
|
provider := FileSystemStorageProvider{
|
|
fileSystem: fileSystem,
|
|
basePath: "/tmp/foo/bar",
|
|
}
|
|
|
|
finalPath, err := provider.StoreExisting("test", "test.bin", "/tmp/existing.bin")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "/tmp/foo/bar/test/test.bin", finalPath)
|
|
|
|
exists, _ := afero.Exists(fileSystem, "/tmp/foo/bar/test/test.bin")
|
|
assert.True(t, exists)
|
|
|
|
content, _ := afero.ReadFile(fileSystem, "/tmp/foo/bar/test/test.bin")
|
|
assert.Equal(t, dummyData, content)
|
|
})
|
|
}
|