fsys/storage_test.go

81 lines
1.6 KiB
Go
Raw Normal View History

2024-11-18 22:34:07 +01:00
package fsys
import (
"github.com/stretchr/testify/assert"
"io"
"testing"
)
func TestStorageLocal(t *testing.T) {
2024-11-18 23:00:58 +01:00
stor, err := New(Config{
2024-11-18 22:34:07 +01:00
Type: "local",
Path: "./test/local",
})
assert.NoError(t, err)
t.Log("== Write ==")
err = stor.Write("test.txt", []byte("hi"), WriteOptions{})
assert.NoError(t, err)
2024-11-18 22:39:35 +01:00
t.Log("== Read ==")
fileContent, err := stor.Read("test.txt")
assert.NoError(t, err)
assert.Equal(t, []byte("hi"), fileContent)
2024-11-18 22:34:07 +01:00
t.Log("== Open ==")
file, err := stor.Open("test.txt")
assert.NoError(t, err)
assert.Equal(t, "test.txt", file.Name)
2024-11-18 22:39:35 +01:00
fileContent, err = io.ReadAll(file)
2024-11-18 22:34:07 +01:00
assert.NoError(t, err)
assert.Equal(t, []byte("hi"), fileContent)
err = file.Close()
assert.NoError(t, err)
t.Log("== Delete ==")
err = stor.Delete("test.txt")
assert.NoError(t, err)
2024-11-18 22:34:07 +01:00
}
func TestStorageS3(t *testing.T) {
2024-11-18 23:00:58 +01:00
stor, err := New(Config{
2024-11-18 22:34:07 +01:00
Type: "s3",
S3BucketName: "test",
S3AccessID: "root",
S3AccessKey: "password123",
S3Endpoint: "127.0.0.1:9000",
})
assert.NoError(t, err)
t.Log("== Write ==")
err = stor.Write("test.txt", []byte("hi"), WriteOptions{})
assert.NoError(t, err)
2024-11-18 22:39:35 +01:00
t.Log("== Read ==")
fileContent, err := stor.Read("test.txt")
assert.NoError(t, err)
assert.Equal(t, []byte("hi"), fileContent)
2024-11-18 22:34:07 +01:00
t.Log("== Open ==")
file, err := stor.Open("test.txt")
assert.NoError(t, err)
assert.Equal(t, "test.txt", file.Name)
2024-11-18 22:39:35 +01:00
fileContent, err = io.ReadAll(file)
2024-11-18 22:34:07 +01:00
assert.NoError(t, err)
assert.Equal(t, []byte("hi"), fileContent)
err = file.Close()
assert.NoError(t, err)
t.Log("== Delete ==")
err = stor.Delete("test.txt")
assert.NoError(t, err)
2024-11-18 22:34:07 +01:00
}