Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
fix:Reslove conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
abyss-w committed Jul 26, 2021
1 parent ada681e commit d62cb3a
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 63 deletions.
154 changes: 117 additions & 37 deletions copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,43 +123,123 @@ func TestCopier(t *testing.T, store types.Storager) {
})
})
})
})
}

func TestCopierWithDir(t *testing.T, store types.Storager) {
Convey("Given a basic Storager", t, func() {
c, ok := store.(types.Copier)
So(ok, ShouldBeTrue)

d := store.(types.Direr)

Convey("When Copy to an existing dir", func() {
srcSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
r := io.LimitReader(randbytes.NewRand(), srcSize)
src := uuid.New().String()

_, err := store.Write(src, r, srcSize)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(src)
if err != nil {
t.Error(err)
}
}()

dst := uuid.New().String()
_, err = d.CreateDir(dst)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(dst, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()

err = c.Copy(src, dst)
Convey("The error should be ErrObjectModeInvalid", func() {
So(errors.Is(err, services.ErrObjectModeInvalid), ShouldBeTrue)
})
})
})
}

func TestCopierWithVirtualDir(t *testing.T, store types.Storager) {
Convey("Given a basic Storager", t, func() {
c, ok := store.(types.Copier)
So(ok, ShouldBeTrue)

d := store.(types.Direr)

Convey("When Copy to an existing dir", func() {
srcSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
r := io.LimitReader(randbytes.NewRand(), srcSize)
src := uuid.New().String()

_, err := store.Write(src, r, srcSize)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(src)
if err != nil {
t.Error(err)
}
}()

dst := uuid.New().String()
_, err = d.CreateDir(dst)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(dst, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()

if d, ok := store.(types.Direr); ok {
Convey("When Copy to an existing dir", func() {
srcSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
r := io.LimitReader(randbytes.NewRand(), srcSize)
src := uuid.New().String()

_, err := store.Write(src, r, srcSize)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(src)
if err != nil {
t.Error(err)
}
}()

dst := uuid.New().String()
_, err = d.CreateDir(dst)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(dst, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()

err = c.Copy(src, dst)
Convey("The error should be ErrObjectModeInvalid", func() {
So(errors.Is(err, services.ErrObjectModeInvalid), ShouldBeTrue)
})
})
}
err = c.Copy(src, dst)

defer func() {
err = store.Delete(dst)
if err != nil {
t.Error(err)
}
}()

Convey("The error should be nil", func() {
So(err, ShouldBeNil)
})

Convey("Stat should get dst object without error", func() {
o, err := store.Stat(dst)

So(err, ShouldBeNil)
So(o, ShouldNotBeNil)

Convey("The Object Mode should be read", func() {
So(o.Mode.IsRead(), ShouldBeTrue)
})

Convey("The path and size should be match", func() {
So(o, ShouldNotBeNil)
So(o.Path, ShouldEqual, dst)

osize, ok := o.GetContentLength()
So(ok, ShouldBeTrue)
So(osize, ShouldEqual, srcSize)
})
})
})
})
}
133 changes: 107 additions & 26 deletions mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,44 +139,125 @@ func TestMover(t *testing.T, store types.Storager) {
})
})
})
})
}

func TestMoverWithDir(t *testing.T, store types.Storager) {
Convey("Given a basic Storager", t, func() {
m, ok := store.(types.Mover)
So(ok, ShouldBeTrue)

d := store.(types.Direr)

Convey("When Move to an existing dir", func() {

srcSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
r := io.LimitReader(randbytes.NewRand(), srcSize)
src := uuid.New().String()

_, err := store.Write(src, r, srcSize)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(src)
if err != nil {
t.Error(err)
}
}()

dst := uuid.New().String()
_, err = d.CreateDir(dst)
if err != nil {
t.Fatal(err)
}

defer func() {
err = store.Delete(dst, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()

err = m.Move(src, dst)
Convey("The error should be ErrObjectModeInvalid", func() {
So(errors.Is(err, services.ErrObjectModeInvalid), ShouldBeTrue)
})
})
})
}

func TestMoverWithVirtualDir(t *testing.T, store types.Storager) {
Convey("Given a basic Storager", t, func() {
m, ok := store.(types.Mover)
So(ok, ShouldBeTrue)

d := store.(types.Direr)

Convey("When Move to an existing dir", func() {

srcSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
r := io.LimitReader(randbytes.NewRand(), srcSize)
src := uuid.New().String()

_, err := store.Write(src, r, srcSize)
if err != nil {
t.Fatal(err)
}

if d, ok := store.(types.Direr); ok {
Convey("When Move to an existing dir", func() {
defer func() {
err = store.Delete(src)
if err != nil {
t.Error(err)
}
}()

srcSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
r := io.LimitReader(randbytes.NewRand(), srcSize)
src := uuid.New().String()
dst := uuid.New().String()
_, err = d.CreateDir(dst)
if err != nil {
t.Fatal(err)
}

_, err := store.Write(src, r, srcSize)
defer func() {
err = store.Delete(dst, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Fatal(err)
t.Error(err)
}
}()

defer func() {
err = store.Delete(src)
if err != nil {
t.Error(err)
}
}()
err = m.Move(src, dst)

dst := uuid.New().String()
_, err = d.CreateDir(dst)
defer func() {
err = store.Delete(dst)
if err != nil {
t.Fatal(err)
t.Error(err)
}
}()

defer func() {
err = store.Delete(dst, pairs.WithObjectMode(types.ModeDir))
if err != nil {
t.Error(err)
}
}()
Convey("The error should be nil", func() {
So(err, ShouldBeNil)
})

Convey("Stat should get dst object without error", func() {
o, err := store.Stat(dst)

So(err, ShouldBeNil)
So(o, ShouldNotBeNil)

err = m.Move(src, dst)
Convey("The error should be ErrObjectModeInvalid", func() {
So(errors.Is(err, services.ErrObjectModeInvalid), ShouldBeTrue)
Convey("The Object Mode should be read", func() {
So(o.Mode.IsRead(), ShouldBeTrue)
})

Convey("The path and size should be match", func() {
So(o, ShouldNotBeNil)
So(o.Path, ShouldEqual, dst)

osize, ok := o.GetContentLength()
So(ok, ShouldBeTrue)
So(osize, ShouldEqual, srcSize)
})
})
}
})
})
}

0 comments on commit d62cb3a

Please sign in to comment.