43 lines
929 B
Go
43 lines
929 B
Go
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")
|
|
}
|
|
}
|