feat: add independent platform modules and multi-provider storage
This commit is contained in:
42
storage/local/local_test.go
Normal file
42
storage/local/local_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.yuntuo.hk/k2safe/go-omni/storage/storagetest"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestContractAndAtomicFailure(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s, err := New(root, 64)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
storagetest.Run(t, s)
|
||||
ctx := context.Background()
|
||||
if _, err = s.Put(ctx, "saved", strings.NewReader("old"), 3, "text/plain"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.Put(ctx, "saved", strings.NewReader("short"), 20, "text/plain"); err == nil {
|
||||
t.Fatal("short upload committed")
|
||||
}
|
||||
again, _ := New(root, 64)
|
||||
object, err := again.Get(ctx, "saved")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := io.ReadAll(object.Body)
|
||||
object.Body.Close()
|
||||
if string(raw) != "old" {
|
||||
t.Fatal(string(raw))
|
||||
}
|
||||
if err = os.Symlink(s.path("saved"), s.path("linked")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.Get(ctx, "linked"); err == nil {
|
||||
t.Fatal("symlink followed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user