-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadonlyAmazonFileSystemTests.cs
More file actions
59 lines (48 loc) · 1.75 KB
/
ReadonlyAmazonFileSystemTests.cs
File metadata and controls
59 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using Ramstack.FileSystem.Specification.Tests;
using Ramstack.FileSystem.Specification.Tests.Utilities;
namespace Ramstack.FileSystem.Amazon;
[TestFixture]
[Category("Cloud:Amazon")]
public class ReadonlyAmazonFileSystemTests : VirtualFileSystemSpecificationTests
{
private readonly TempFileStorage _storage = new TempFileStorage();
[OneTimeSetUp]
public async Task Setup()
{
using var fs = CreateFileSystem(isReadOnly: false);
await fs.CreateBucketAsync();
foreach (var path in Directory.EnumerateFiles(_storage.Root, "*", SearchOption.AllDirectories))
{
await using var stream = File.OpenRead(path);
await fs.WriteAsync(path[_storage.Root.Length..], stream, overwrite: true);
}
}
[OneTimeTearDown]
public async Task Cleanup()
{
_storage.Dispose();
using var fs = CreateFileSystem(isReadOnly: false);
await fs.DeleteDirectoryAsync("/");
}
protected override AmazonS3FileSystem GetFileSystem() =>
CreateFileSystem(isReadOnly: true);
protected override DirectoryInfo GetDirectoryInfo() =>
new DirectoryInfo(_storage.Root);
private AmazonS3FileSystem CreateFileSystem(bool isReadOnly)
{
var credentials = new BasicAWSCredentials("rustfsadmin", "rustfsadmin");
var config = new AmazonS3Config
{
RegionEndpoint = RegionEndpoint.USEast1,
ServiceURL = "http://localhost:9000",
ForcePathStyle = true,
};
return new AmazonS3FileSystem(credentials, config, bucketName: "storage")
{
IsReadOnly = isReadOnly
};
}
}