-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
private/object: add StatObject to get specific object version
New method to stat not only latest version of object but also other existing versions. storj/storj#6221 Change-Id: Icab5959f533463cab80e5ef20baaa1b725443a82
- Loading branch information
Showing
7 changed files
with
139 additions
and
34 deletions.
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
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
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
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
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
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,65 @@ | ||
// Copyright (C) 2023 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package object_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"storj.io/common/memory" | ||
"storj.io/common/testcontext" | ||
"storj.io/common/testrand" | ||
"storj.io/storj/private/testplanet" | ||
"storj.io/uplink" | ||
"storj.io/uplink/private/object" | ||
) | ||
|
||
func TestStatObject(t *testing.T) { | ||
testplanet.Run(t, testplanet.Config{ | ||
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1, | ||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { | ||
bucketName := "test-bucket" | ||
objectKey := "test-object" | ||
err := planet.Uplinks[0].CreateBucket(ctx, planet.Satellites[0], bucketName) | ||
require.NoError(t, err) | ||
|
||
project, err := planet.Uplinks[0].OpenProject(ctx, planet.Satellites[0]) | ||
require.NoError(t, err) | ||
defer ctx.Check(project.Close) | ||
|
||
_, err = object.StatObject(ctx, project, "", "", nil) | ||
require.ErrorIs(t, err, uplink.ErrBucketNameInvalid) | ||
|
||
_, err = object.StatObject(ctx, project, bucketName, "", nil) | ||
require.ErrorIs(t, err, uplink.ErrObjectKeyInvalid) | ||
|
||
_, err = object.StatObject(ctx, project, "non-existing-bucket", objectKey, nil) | ||
require.ErrorIs(t, err, uplink.ErrObjectNotFound) | ||
|
||
_, err = object.StatObject(ctx, project, bucketName, "non-existing-object", nil) | ||
require.ErrorIs(t, err, uplink.ErrObjectNotFound) | ||
|
||
err = planet.Uplinks[0].Upload(ctx, planet.Satellites[0], bucketName, objectKey, testrand.Bytes(memory.KiB)) | ||
require.NoError(t, err) | ||
|
||
obj, err := object.StatObject(ctx, project, bucketName, objectKey, nil) | ||
require.NoError(t, err) | ||
require.Equal(t, objectKey, obj.Key) | ||
require.NotZero(t, obj.Version) | ||
|
||
// try to stat specific version | ||
objTwo, err := object.StatObject(ctx, project, bucketName, objectKey, obj.Version) | ||
require.NoError(t, err) | ||
require.Equal(t, objectKey, objTwo.Key) | ||
require.Equal(t, obj.Version, objTwo.Version) | ||
|
||
// try to stat NOT EXISTING version | ||
_, err = object.StatObject(ctx, project, bucketName, objectKey, []byte{1, 2, 3, 4, 5, 6, 7, 8}) | ||
require.ErrorIs(t, err, uplink.ErrObjectNotFound) | ||
}) | ||
} | ||
|
||
// TODO(ver) add tests for versioned/unversioned/suspended objects as well as delete markers | ||
// for all methods from 'object' package |
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