63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
|
package fsys
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"io"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestStorageLocal(t *testing.T) {
|
||
|
|
||
|
stor, err := New(&Config{
|
||
|
Type: "local",
|
||
|
Path: "./test/local",
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
t.Log("== Write ==")
|
||
|
err = stor.Write("test.txt", []byte("hi"), WriteOptions{})
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
t.Log("== Open ==")
|
||
|
file, err := stor.Open("test.txt")
|
||
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, "test.txt", file.Name)
|
||
|
|
||
|
fileContent, err := io.ReadAll(file)
|
||
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, []byte("hi"), fileContent)
|
||
|
|
||
|
err = file.Close()
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestStorageS3(t *testing.T) {
|
||
|
|
||
|
stor, err := New(&Config{
|
||
|
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)
|
||
|
|
||
|
t.Log("== Open ==")
|
||
|
file, err := stor.Open("test.txt")
|
||
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, "test.txt", file.Name)
|
||
|
|
||
|
fileContent, err := io.ReadAll(file)
|
||
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, []byte("hi"), fileContent)
|
||
|
|
||
|
err = file.Close()
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
}
|