diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-05-07 13:42:12 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-05-07 13:42:12 +0200 |
| commit | 17e9003342f79313d4b919818db6f69964d102db (patch) | |
| tree | d1167df5e0e835b099b6c0c8ca8a1688b650bf6b /tests | |
| parent | b94608f789ad89dcecd4e02328e79787d4342a94 (diff) | |
| download | go-schwift-17e9003342f79313d4b919818db6f69964d102db.tar.gz | |
add Object.SymlinkTo(), Object.InspectSymlink() etc.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/object_test.go | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/tests/object_test.go b/tests/object_test.go index 8b5dc0e..618c835 100644 --- a/tests/object_test.go +++ b/tests/object_test.go @@ -187,7 +187,7 @@ func TestObjectUpdate(t *testing.T) { }) } -func TestObjectCopyMove(t *testing.T) { +func TestObjectCopy(t *testing.T) { testWithContainer(t, func(c *schwift.Container) { obj1 := c.Object("location1") err := obj1.Upload(bytes.NewReader(objectExampleContent), nil, nil) @@ -202,6 +202,58 @@ func TestObjectCopyMove(t *testing.T) { }) } +func TestSymlinkOperations(t *testing.T) { + testWithContainer(t, func(c *schwift.Container) { + //create a test object that we can link to + obj1 := c.Object("target") + err := obj1.Upload(bytes.NewReader(objectExampleContent), nil, nil) + expectSuccess(t, err) + expectObjectExistence(t, obj1, true) + + //create a symlink + obj2 := c.Object("symlink") + expectSuccess(t, obj2.SymlinkTo(obj1, nil, nil)) + expectObjectExistence(t, obj2, true) + expectObjectSymlink(t, obj2, obj1) + expectObjectContent(t, obj2, objectExampleContent) + + //overwrite symlink with normal object + otherContent := []byte("abc") + expectSuccess(t, obj2.Upload(bytes.NewReader(otherContent), nil, nil)) + expectObjectExistence(t, obj2, true) + expectObjectSymlink(t, obj2, nil) + expectObjectContent(t, obj2, otherContent) + + //overwrite normal object with symlink + expectSuccess(t, obj2.SymlinkTo(obj1, nil, nil)) + expectObjectExistence(t, obj2, true) + expectObjectSymlink(t, obj2, obj1) + expectObjectContent(t, obj2, objectExampleContent) + + //deep-copy symlink + obj3 := c.Object("copy") + expectSuccess(t, obj2.CopyTo(obj3, nil, nil)) + expectObjectExistence(t, obj3, true) + expectObjectSymlink(t, obj3, nil) + expectObjectContent(t, obj3, objectExampleContent) + + //shallow-copy symlink + expectSuccess(t, obj2.CopyTo(obj3, &schwift.CopyOptions{ + ShallowCopySymlinks: true, + }, nil)) + expectObjectExistence(t, obj3, true) + expectObjectSymlink(t, obj3, obj1) + expectObjectContent(t, obj3, objectExampleContent) + + //delete symlink + expectSuccess(t, obj2.Delete(nil, nil)) + expectObjectExistence(t, obj2, false) + }) +} + +//////////////////////////////////////////////////////////////////////////////// +// helpers + func expectObjectExistence(t *testing.T, obj *schwift.Object, expectedExists bool) { t.Helper() obj.Invalidate() @@ -222,3 +274,28 @@ func expectObjectContent(t *testing.T, obj *schwift.Object, expected []byte) { expectString(t, hdr.Etag().Get(), etagOf(expected)) } } + +func expectObjectSymlink(t *testing.T, source, expectedTarget *schwift.Object) { + t.Helper() + target, _, err := source.InspectSymlink() + if expectedTarget == nil { + switch err { + case schwift.ErrNotASymlink: + return //success + case nil: + t.Errorf("expected %s to not be a symlink, but found symlink to %s\n", + source.FullName(), target.FullName()) + default: + t.Errorf("got unexpected error from Object.SymlinkTarget() for %s: %s\n", + source.FullName(), err.Error()) + } + } else { + if err != nil { + t.Errorf("expected %s to be a symlink to %s, but Object.SymlinkTarget() returned error: %s\n", + source.FullName(), expectedTarget.FullName(), err.Error()) + } else if target.FullName() != expectedTarget.FullName() { + t.Errorf("expected %s to be a symlink to %s, but got target %s\n", + source.FullName(), expectedTarget.FullName(), target.FullName()) + } + } +} |
