This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
test: Implement GSP-86 Add linker integration tests #40
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4febc85
test: Implement GSP-86 Add linker integration tests
abyss-w 59819a5
test:Add some cases to linker integration tests
abyss-w ada681e
test: Modify some cases in linker integration test
abyss-w 4149141
fix: Resolve conflicts
abyss-w 225fc35
fix: Resolve conflicts
abyss-w 9fec99f
Merge branch 'beyondstorage-master'
abyss-w 73e60b8
test: Add some cases in linker integration test
abyss-w 143db36
revert: Removing the parts we haven't agreed on yet
abyss-w 7a59090
fix: Delete Read should get path object data without error
abyss-w 5937518
test: Modified a few minor areas
abyss-w 1aae100
Merge branch 'master' into master
abyss-w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
*.yaml | ||
*.yaml | ||
|
||
# Jetbrain IDE | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
package tests | ||
|
||
import ( | ||
"bytes" | ||
"crypto/md5" | ||
"io" | ||
"io/ioutil" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
. "github.com/smartystreets/goconvey/convey" | ||
|
||
"github.com/beyondstorage/go-storage/v4/pkg/randbytes" | ||
"github.com/beyondstorage/go-storage/v4/types" | ||
) | ||
|
||
func TestLinker(t *testing.T, store types.Storager) { | ||
Convey("Given a basic Storager", t, func() { | ||
l, ok := store.(types.Linker) | ||
So(ok, ShouldBeTrue) | ||
|
||
Convey("When create a link object", func() { | ||
size := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB | ||
r := io.LimitReader(randbytes.NewRand(), size) | ||
target := uuid.New().String() | ||
|
||
_, err := store.Write(target, r, size) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
err = store.Delete(target) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
|
||
path := uuid.New().String() | ||
o, err := l.CreateLink(path, target) | ||
|
||
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 link", func() { | ||
// Link object's mode must be link. | ||
So(o.Mode.IsLink(), ShouldBeTrue) | ||
}) | ||
|
||
Convey("The linkTarget of the object must be the same as the target", func() { | ||
// The linkTarget must be the same as the target. | ||
linkTarget, ok := o.GetLinkTarget() | ||
|
||
So(ok, ShouldBeTrue) | ||
So(linkTarget, ShouldEqual, target) | ||
}) | ||
|
||
Convey("Stat should get path object without error", func() { | ||
obj, err := store.Stat(path) | ||
|
||
Convey("The error should be nil", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
Convey("The object mode should be link", func() { | ||
// Link object's mode must be link. | ||
So(obj.Mode.IsLink(), ShouldBeTrue) | ||
}) | ||
|
||
Convey("The linkTarget of the object must be the same as the target", func() { | ||
// The linkTarget must be the same as the target. | ||
linkTarget, ok := obj.GetLinkTarget() | ||
|
||
So(ok, ShouldBeTrue) | ||
So(linkTarget, ShouldEqual, target) | ||
}) | ||
}) | ||
}) | ||
|
||
Convey("When create a link object from a not existing target", func() { | ||
target := uuid.New().String() | ||
|
||
path := uuid.New().String() | ||
o, err := l.CreateLink(path, target) | ||
|
||
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 link", func() { | ||
// Link object's mode must be link. | ||
So(o.Mode.IsLink(), ShouldBeTrue) | ||
}) | ||
|
||
Convey("The linkTarget of the object must be the same as the target", func() { | ||
linkTarget, ok := o.GetLinkTarget() | ||
|
||
So(ok, ShouldBeTrue) | ||
So(linkTarget, ShouldEqual, target) | ||
}) | ||
|
||
Convey("Stat should get path object without error", func() { | ||
obj, err := store.Stat(path) | ||
|
||
Convey("The error should be nil", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
Convey("The object mode should be link", func() { | ||
// Link object's mode must be link. | ||
So(obj.Mode.IsLink(), ShouldBeTrue) | ||
}) | ||
|
||
Convey("The linkTarget of the object must be the same as the target", func() { | ||
// The linkTarget must be the same as the target. | ||
linkTarget, ok := obj.GetLinkTarget() | ||
|
||
So(ok, ShouldBeTrue) | ||
So(linkTarget, ShouldEqual, target) | ||
}) | ||
}) | ||
|
||
size := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB | ||
content, _ := ioutil.ReadAll(io.LimitReader(randbytes.NewRand(), size)) | ||
|
||
_, err = store.Write(target, bytes.NewReader(content), size) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
err = store.Delete(target) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
|
||
Convey("Read should get path object data without error", func() { | ||
var buf bytes.Buffer | ||
n, err := store.Read(path, &buf) | ||
|
||
Convey("The error should be nil", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
Convey("The content should be match", func() { | ||
So(buf, ShouldNotBeNil) | ||
So(n, ShouldEqual, size) | ||
So(md5.Sum(buf.Bytes()), ShouldResemble, md5.Sum(content)) | ||
}) | ||
}) | ||
}) | ||
|
||
Convey("When CreateLink to an existing path", func() { | ||
firstSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB | ||
r := io.LimitReader(randbytes.NewRand(), firstSize) | ||
firstTarget := uuid.New().String() | ||
|
||
_, err := store.Write(firstTarget, r, firstSize) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
err = store.Delete(firstTarget) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
|
||
path := uuid.New().String() | ||
o, err := l.CreateLink(path, firstTarget) | ||
|
||
defer func() { | ||
err = store.Delete(path) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
|
||
Convey("The first returned error should be nil", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
secondSize := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB | ||
secondContent, _ := ioutil.ReadAll(io.LimitReader(randbytes.NewRand(), secondSize)) | ||
secondTarget := uuid.New().String() | ||
|
||
_, err = store.Write(secondTarget, bytes.NewReader(secondContent), secondSize) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
err = store.Delete(secondTarget) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}() | ||
|
||
o, err = l.CreateLink(path, secondTarget) | ||
|
||
Convey("The second returned error should also be nil", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
Convey("The object mode should be link", func() { | ||
// Link object's mode must be link. | ||
So(o.Mode.IsLink(), ShouldBeTrue) | ||
}) | ||
|
||
Convey("The linkTarget of the object must be the same as the secondTarget", func() { | ||
// The linkTarget must be the same as the secondTarget. | ||
linkTarget, ok := o.GetLinkTarget() | ||
|
||
So(ok, ShouldBeTrue) | ||
So(linkTarget, ShouldEqual, secondTarget) | ||
}) | ||
|
||
Convey("Read should get path object data without error", func() { | ||
var buf bytes.Buffer | ||
n, err := store.Read(path, &buf) | ||
|
||
Convey("The error should be nil", func() { | ||
So(err, ShouldBeNil) | ||
}) | ||
|
||
Convey("The content should be match", func() { | ||
// The content should match the secondTarget | ||
So(buf, ShouldNotBeNil) | ||
So(n, ShouldEqual, secondSize) | ||
So(md5.Sum(buf.Bytes()), ShouldResemble, md5.Sum(secondContent)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LinkObject
is not readable, so we can't read from a link directly. Instead, we need to read from the link object'sLinkTarget
.Maybe we can remove tests about
Read should get path object data without error
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!