diff --git a/copier.go b/copier.go index 06af0ed..0fd814e 100644 --- a/copier.go +++ b/copier.go @@ -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) + }) + }) + }) }) } diff --git a/go.mod b/go.mod index f718ecc..cb24463 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/beyondstorage/go-integration-test/v4 go 1.15 require ( - github.com/beyondstorage/go-storage/v4 v4.3.2 + github.com/beyondstorage/go-storage/v4 v4.4.0 github.com/google/uuid v1.3.0 github.com/smartystreets/goconvey v1.6.4 ) diff --git a/go.sum b/go.sum index f8f8211..deb14a2 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/Xuanwo/templateutils v0.1.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8= -github.com/beyondstorage/go-storage/v4 v4.3.2 h1:F3xQVTcBJ+nSzEt/wBZCx4pE7aYhy43+tn1mwMYCacE= -github.com/beyondstorage/go-storage/v4 v4.3.2/go.mod h1:8FHjTUFuwLl/mmIGpOL9g3RTZPyye7vneFN/JkRj5Tg= +github.com/beyondstorage/go-storage/v4 v4.4.0 h1:sWURraKFjNR4qpwthr45cAGOIx6EOLrrJcz6su4Je30= +github.com/beyondstorage/go-storage/v4 v4.4.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU= github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ= github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= @@ -11,7 +11,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/pprof v0.0.0-20181127221834-b4f47329b966/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= diff --git a/mover.go b/mover.go index b380e76..10d886a 100644 --- a/mover.go +++ b/mover.go @@ -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) }) }) - } + }) }) }