-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3f0f6a
commit ae28cb4
Showing
11 changed files
with
456 additions
and
7 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
49 changes: 49 additions & 0 deletions
49
apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1.IntegrationTests/RestoreObjectTest.cs
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,49 @@ | ||
// Copyright 2024 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Cloud.ClientTesting; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Google.Cloud.Storage.V1.IntegrationTests | ||
{ | ||
[Collection(nameof(StorageFixture))] | ||
public class RestoreObjectTest | ||
{ | ||
private readonly StorageFixture _fixture; | ||
|
||
public RestoreObjectTest(StorageFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task RestoresObject() | ||
{ | ||
// We upload and delete an object on the soft delete bucket. | ||
var uploaded = await _fixture.Client.UploadObjectAsync(_fixture.SoftDeleteBucket, IdGenerator.FromGuid(prefix: "restore-soft-delete"), "text/plain", new MemoryStream(_fixture.SmallContent)); | ||
await _fixture.Client.DeleteObjectAsync(uploaded); | ||
|
||
// And now we can restore it. | ||
await _fixture.Client.RestoreObjectAsync(_fixture.SoftDeleteBucket, uploaded.Name, uploaded.Generation.Value); | ||
|
||
var restored = await _fixture.Client.GetObjectAsync(_fixture.SoftDeleteBucket, uploaded.Name); | ||
Assert.Equal(_fixture.SoftDeleteBucket, restored.Bucket); | ||
Assert.Equal(uploaded.Name, restored.Name); | ||
Assert.Equal((ulong) _fixture.SmallContent.Length, restored.Size); | ||
Assert.Null(restored.SoftDeleteTimeDateTimeOffset); | ||
} | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1.Tests/RestoreObjectOptionsTest.cs
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,96 @@ | ||
// Copyright 2024 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using Xunit; | ||
using static Google.Apis.Storage.v1.ObjectsResource; | ||
using static Google.Apis.Storage.v1.ObjectsResource.RestoreRequest; | ||
using Object = Google.Apis.Storage.v1.Data.Object; | ||
|
||
namespace Google.Cloud.Storage.V1.Tests; | ||
|
||
public class RestoreObjectOptionsTest | ||
{ | ||
[Fact] | ||
public void ModifyRequest_DefaultOptions() | ||
{ | ||
var request = new RestoreRequest(null, "bucket", "object", 2L); | ||
var options = new RestoreObjectOptions(); | ||
options.ModifyRequest(request); | ||
Assert.Null(request.IfGenerationMatch); | ||
Assert.Null(request.IfGenerationNotMatch); | ||
Assert.Null(request.IfMetagenerationMatch); | ||
Assert.Null(request.IfMetagenerationNotMatch); | ||
Assert.Null(request.CopySourceAcl); | ||
Assert.Null(request.Projection); | ||
Assert.Null(request.UserProject); | ||
} | ||
|
||
[Fact] | ||
public void ModifyRequest_PositiveMatchOptions() | ||
{ | ||
var request = new RestoreRequest(null, "bucket", "object", 2L); | ||
var options = new RestoreObjectOptions | ||
{ | ||
IfGenerationMatch = 1L, | ||
IfMetagenerationMatch = 2L, | ||
CopySourceAcl = true, | ||
Projection = Projection.Full, | ||
UserProject = "proj" | ||
}; | ||
options.ModifyRequest(request); | ||
Assert.Equal(1L, request.IfGenerationMatch); | ||
Assert.Null(request.IfGenerationNotMatch); | ||
Assert.Equal(2L, request.IfMetagenerationMatch); | ||
Assert.Null(request.IfMetagenerationNotMatch); | ||
Assert.True(request.CopySourceAcl); | ||
Assert.Equal(ProjectionEnum.Full, request.Projection); | ||
Assert.Equal("proj", request.UserProject); | ||
} | ||
|
||
[Fact] | ||
public void ModifyRequest_NegativeMatchOptions() | ||
{ | ||
var request = new RestoreRequest(null, "bucket", "object", 2L); | ||
var options = new RestoreObjectOptions | ||
{ | ||
IfGenerationNotMatch = 1L, | ||
IfMetagenerationNotMatch = 2L, | ||
Projection = Projection.Full | ||
}; | ||
options.ModifyRequest(request); | ||
Assert.Null(request.IfGenerationMatch); | ||
Assert.Equal(1L, request.IfGenerationNotMatch); | ||
Assert.Null(request.IfMetagenerationMatch); | ||
Assert.Equal(2L, request.IfMetagenerationNotMatch); | ||
Assert.Equal(ProjectionEnum.Full, request.Projection); | ||
} | ||
|
||
[Fact] | ||
public void ModifyRequest_MatchNotMatchConflicts() | ||
{ | ||
var request = new RestoreRequest(null, "bucket", "object", 2L); | ||
Assert.Throws<ArgumentException>(() => | ||
{ | ||
var options = new RestoreObjectOptions { IfGenerationMatch = 1L, IfGenerationNotMatch = 2L }; | ||
options.ModifyRequest(request); | ||
}); | ||
Assert.Throws<ArgumentException>(() => | ||
{ | ||
var options = new RestoreObjectOptions { IfMetagenerationMatch = 1L, IfMetagenerationNotMatch = 2L }; | ||
options.ModifyRequest(request); | ||
}); | ||
} | ||
|
||
} |
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
Oops, something went wrong.