fix read for s3, add test for read
This commit is contained in:
parent
17896c3cc4
commit
41e7d6070d
2 changed files with 18 additions and 4 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -136,10 +137,11 @@ func (s *Storage) Read(name string) ([]byte, error) {
|
|||
}
|
||||
}
|
||||
|
||||
var objectBytes []byte
|
||||
if _, err := object.Read(objectBytes); err != nil {
|
||||
objectBytes, err := io.ReadAll(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return objectBytes, nil
|
||||
} else {
|
||||
return os.ReadFile(filepath.Join(s.config.Path, name))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package fsys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io"
|
||||
"testing"
|
||||
|
@ -18,12 +19,17 @@ func TestStorageLocal(t *testing.T) {
|
|||
err = stor.Write("test.txt", []byte("hi"), WriteOptions{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Log("== Read ==")
|
||||
fileContent, err := stor.Read("test.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("hi"), fileContent)
|
||||
|
||||
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)
|
||||
fileContent, err = io.ReadAll(file)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("hi"), fileContent)
|
||||
|
||||
|
@ -47,12 +53,18 @@ func TestStorageS3(t *testing.T) {
|
|||
err = stor.Write("test.txt", []byte("hi"), WriteOptions{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Log("== Read ==")
|
||||
fileContent, err := stor.Read("test.txt")
|
||||
assert.NoError(t, err)
|
||||
fmt.Println(fileContent)
|
||||
assert.Equal(t, []byte("hi"), fileContent)
|
||||
|
||||
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)
|
||||
fileContent, err = io.ReadAll(file)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []byte("hi"), fileContent)
|
||||
|
||||
|
|
Loading…
Reference in a new issue