fix: copyObject restore with a specific version, update test cases (#19895)

This commit is contained in:
jiuker
2024-06-10 23:50:49 +08:00
committed by GitHub
parent a2cab02554
commit 0662c90b5c
7 changed files with 157 additions and 68 deletions

View File

@@ -1540,7 +1540,7 @@ func removeRoots(roots []string) {
// initializes the specified API endpoints for the tests.
// initializes the root and returns its path.
// return credentials.
func initAPIHandlerTest(ctx context.Context, obj ObjectLayer, endpoints []string) (string, http.Handler, error) {
func initAPIHandlerTest(ctx context.Context, obj ObjectLayer, endpoints []string, makeBucketOptions MakeBucketOptions) (string, http.Handler, error) {
initAllSubsystems(ctx)
initConfigSubsystem(ctx, obj)
@@ -1549,9 +1549,8 @@ func initAPIHandlerTest(ctx context.Context, obj ObjectLayer, endpoints []string
// get random bucket name.
bucketName := getRandomBucketName()
// Create bucket.
err := obj.MakeBucket(context.Background(), bucketName, MakeBucketOptions{})
err := obj.MakeBucket(context.Background(), bucketName, makeBucketOptions)
if err != nil {
// failed to create newbucket, return err.
return "", nil, err
@@ -1741,9 +1740,17 @@ func ExecObjectLayerAPINilTest(t TestErrHandler, bucketName, objectName, instanc
}
}
type ExecObjectLayerAPITestArgs struct {
t *testing.T
objAPITest objAPITestType
endpoints []string
init func()
makeBucketOptions MakeBucketOptions
}
// ExecObjectLayerAPITest - executes object layer API tests.
// Creates single node and Erasure ObjectLayer instance, registers the specified API end points and runs test for both the layers.
func ExecObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints []string) {
func ExecObjectLayerAPITest(args ExecObjectLayerAPITestArgs) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -1753,24 +1760,28 @@ func ExecObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints [
objLayer, fsDir, err := prepareFS(ctx)
if err != nil {
t.Fatalf("Initialization of object layer failed for single node setup: %s", err)
args.t.Fatalf("Initialization of object layer failed for single node setup: %s", err)
}
bucketFS, fsAPIRouter, err := initAPIHandlerTest(ctx, objLayer, endpoints)
bucketFS, fsAPIRouter, err := initAPIHandlerTest(ctx, objLayer, args.endpoints, args.makeBucketOptions)
if err != nil {
t.Fatalf("Initialization of API handler tests failed: <ERROR> %s", err)
args.t.Fatalf("Initialization of API handler tests failed: <ERROR> %s", err)
}
if args.init != nil {
args.init()
}
// initialize the server and obtain the credentials and root.
// credentials are necessary to sign the HTTP request.
if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil {
t.Fatalf("Unable to initialize server config. %s", err)
args.t.Fatalf("Unable to initialize server config. %s", err)
}
credentials := globalActiveCred
// Executing the object layer tests for single node setup.
objAPITest(objLayer, ErasureSDStr, bucketFS, fsAPIRouter, credentials, t)
args.objAPITest(objLayer, ErasureSDStr, bucketFS, fsAPIRouter, credentials, args.t)
// reset globals.
// this is to make sure that the tests are not affected by modified value.
@@ -1778,23 +1789,27 @@ func ExecObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints [
objLayer, erasureDisks, err := prepareErasure16(ctx)
if err != nil {
t.Fatalf("Initialization of object layer failed for Erasure setup: %s", err)
args.t.Fatalf("Initialization of object layer failed for Erasure setup: %s", err)
}
defer objLayer.Shutdown(ctx)
bucketErasure, erAPIRouter, err := initAPIHandlerTest(ctx, objLayer, endpoints)
bucketErasure, erAPIRouter, err := initAPIHandlerTest(ctx, objLayer, args.endpoints, args.makeBucketOptions)
if err != nil {
t.Fatalf("Initialization of API handler tests failed: <ERROR> %s", err)
args.t.Fatalf("Initialization of API handler tests failed: <ERROR> %s", err)
}
if args.init != nil {
args.init()
}
// initialize the server and obtain the credentials and root.
// credentials are necessary to sign the HTTP request.
if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil {
t.Fatalf("Unable to initialize server config. %s", err)
args.t.Fatalf("Unable to initialize server config. %s", err)
}
// Executing the object layer tests for Erasure.
objAPITest(objLayer, ErasureTestStr, bucketErasure, erAPIRouter, credentials, t)
args.objAPITest(objLayer, ErasureTestStr, bucketErasure, erAPIRouter, credentials, args.t)
// clean up the temporary test backend.
removeRoots(append(erasureDisks, fsDir))
@@ -1803,8 +1818,8 @@ func ExecObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints [
// ExecExtendedObjectLayerTest will execute the tests with combinations of encrypted & compressed.
// This can be used to test functionality when reading and writing data.
func ExecExtendedObjectLayerAPITest(t *testing.T, objAPITest objAPITestType, endpoints []string) {
execExtended(t, func(t *testing.T) {
ExecObjectLayerAPITest(t, objAPITest, endpoints)
execExtended(t, func(t *testing.T, init func(), makeBucketOptions MakeBucketOptions) {
ExecObjectLayerAPITest(ExecObjectLayerAPITestArgs{t: t, objAPITest: objAPITest, endpoints: endpoints, init: init, makeBucketOptions: makeBucketOptions})
})
}