Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): Move go-integration-tests here #847

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ bin/
release/
coverage/
coverage.*
tests/*.yaml

# Jetbrain IDE
.idea
*.iml
*.iml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ require (
github.com/Xuanwo/templateutils v0.1.0
github.com/dave/dst v0.26.2
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/kevinburke/go-bindata v3.22.0+incompatible
github.com/pelletier/go-toml v1.9.4
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/goconvey v1.6.6
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
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.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=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kevinburke/go-bindata v3.22.0+incompatible h1:/JmqEhIWQ7GRScV0WjX/0tqBrC5D21ALg0H0U/KZ/ts=
github.com/kevinburke/go-bindata v3.22.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand All @@ -39,6 +45,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.6 h1:lH+Snxmzl92r1jww8/jYPqKkhs3C9AF4LunzU56ZZr4=
github.com/smartystreets/goconvey v1.6.6/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand All @@ -53,6 +63,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -72,6 +83,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
Expand Down
3 changes: 3 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Storage Integration Test

This package designed for integration test.
179 changes: 179 additions & 0 deletions tests/appender.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package tests

import (
"bytes"
"crypto/sha256"
"io"
"io/ioutil"
"math/rand"
"testing"

"github.com/google/uuid"
. "github.com/smartystreets/goconvey/convey"

"go.beyondstorage.io/v5/pairs"
"go.beyondstorage.io/v5/pkg/randbytes"
"go.beyondstorage.io/v5/types"
)

func TestAppender(t *testing.T, store types.Storager) {
Convey("Given a basic Storager", t, func() {
ap, ok := store.(types.Appender)
So(ok, ShouldBeTrue)

Convey("When CreateAppend", func() {
path := uuid.NewString()
o, err := ap.CreateAppend(path)

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

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

Convey("The Object Mode should be appendable", func() {
// Append object's mode must be appendable.
So(o.Mode.IsAppend(), ShouldBeTrue)
})
})

Convey("When CreateAppend with an existing object", func() {
path := uuid.NewString()
o, err := ap.CreateAppend(path)

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

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

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

_, err = ap.WriteAppend(o, r, size)
if err != nil {
t.Fatal(err)
}

err = ap.CommitAppend(o)
if err != nil {
t.Fatal(err)
}

o, err = ap.CreateAppend(path)

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

Convey("The Object Mode should be appendable", func() {
// Append object's mode must be appendable.
So(o.Mode.IsAppend(), ShouldBeTrue)
})

Convey("The object append offset should be 0", func() {
So(o.MustGetAppendOffset(), ShouldBeZeroValue)
})
})

Convey("When Delete", func() {
path := uuid.NewString()
_, err := ap.CreateAppend(path)
if err != nil {
t.Error(err)
}

err = store.Delete(path)
Convey("The first returned error should be nil", func() {
So(err, ShouldBeNil)
})

err = store.Delete(path)
Convey("The second returned error also should be nil", func() {
So(err, ShouldBeNil)
})
})

Convey("When WriteAppend", func() {
path := uuid.NewString()
o, err := ap.CreateAppend(path)
if err != nil {
t.Error(err)
}

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

size := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
content, _ := ioutil.ReadAll(io.LimitReader(randbytes.NewRand(), size))
r := bytes.NewReader(content)

n, err := ap.WriteAppend(o, r, size)

Convey("WriteAppend error should be nil", func() {
So(err, ShouldBeNil)
})
Convey("WriteAppend size should be equal to n", func() {
So(n, ShouldEqual, size)
})
})

Convey("When CommitAppend", func() {
path := uuid.NewString()
o, err := ap.CreateAppend(path)
if err != nil {
t.Error(err)
}

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

size := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
content, _ := ioutil.ReadAll(io.LimitReader(randbytes.NewRand(), size))

_, err = ap.WriteAppend(o, bytes.NewReader(content), size)
if err != nil {
t.Error(err)
}

_, err = ap.WriteAppend(o, bytes.NewReader(content), size)
if err != nil {
t.Error(err)
}

err = ap.CommitAppend(o)

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

var buf bytes.Buffer
_, err = store.Read(path, &buf, pairs.WithSize(size*2))

Convey("Read error should be nil", func() {
So(err, ShouldBeNil)
})
Convey("The content should be match", func() {
So(sha256.Sum256(buf.Bytes()), ShouldResemble, sha256.Sum256(bytes.Repeat(content, 2)))
})
})
})
}
Loading