Skip to content

Commit 57c1b6d

Browse files
committed
added loose files test
1 parent 0bc8d58 commit 57c1b6d

File tree

6 files changed

+76
-38
lines changed

6 files changed

+76
-38
lines changed

.github/workflows/dotnet.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ name: Build and Test
55

66
on:
77
push:
8-
branches: [ "master" ]
9-
pull_request:
10-
branches: [ "master" ]
118

129
jobs:
1310
Build_and_Test:
@@ -29,6 +26,9 @@ jobs:
2926
run: dotnet build --no-restore
3027

3128
- name: Test
29+
env:
30+
MINIO_ACCESS_KEY: ${{ secrets.MINIO_ACCESS_KEY }}
31+
MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }}
3232
run: dotnet test --no-build --verbosity normal
3333

3434
Build_and_Test_Linux:

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
2727
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.5" />
2828
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="9.0.5" />
29+
<PackageVersion Include="Minio" Version="6.0.4" />
2930
<PackageVersion Include="Moq" Version="4.20.72" />
3031
<PackageVersion Include="Projektanker.Icons.Avalonia.FontAwesome" Version="9.6.2" />
3132
<PackageVersion Include="Roslynator.Analyzers" Version="4.13.1" />
@@ -36,7 +37,6 @@
3637
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
3738
<PackageVersion Include="xunit" Version="2.9.3" />
3839
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0" />
39-
<PackageVersion Include="AWSSDK.S3" Version="4.0.0.3" />
4040
<PackageVersion Include="ConfigureAwaitAnalyzer" Version="1.1.0" />
4141
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />
4242
<PackageVersion Include="Microsoft.AspNetCore.SpaProxy" Version="9.0.5" />

Web.Blazor/Helpers/S3Client.cs

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,19 @@
1-
using Amazon.Runtime;
2-
using Amazon.S3;
3-
using Amazon.S3.Model;
4-
5-
namespace Web.Blazor.Helpers;
1+
namespace Web.Blazor.Helpers;
62

73
public sealed class S3Client : IDisposable
84
{
9-
private readonly string _key = Environment.GetEnvironmentVariable("S3Key")!;
10-
private readonly string _secretKey = Environment.GetEnvironmentVariable("S3SKey")!;
11-
12-
private readonly AmazonS3Client _s3client;
13-
14-
public S3Client()
15-
{
16-
AmazonS3Config config = new()
17-
{
18-
ServiceURL = "https://s3.timeweb.cloud",
19-
UseHttp = false
20-
};
21-
22-
AWSCredentials creds = new BasicAWSCredentials(_key, _secretKey);
23-
_s3client = new(creds, config);
24-
}
25-
265
/// <summary>
276
/// Get signed URL for file uploading
287
/// </summary>
298
/// <param name="file">File name</param>
309
/// <returns>Signed URL</returns>
3110
public string GetSignedUrl(string file)
3211
{
33-
GetPreSignedUrlRequest request = new()
34-
{
35-
//BucketName = Consts.Bucket,
36-
Key = file,
37-
Expires = DateTime.Now.AddHours(1),
38-
Verb = HttpVerb.PUT
39-
};
12+
return string.Empty;
13+
}
4014

41-
var url = _s3client.GetPreSignedURL(request);
15+
public void Dispose()
16+
{
4217

43-
return url;
4418
}
45-
46-
public void Dispose() => _s3client?.Dispose();
4719
}

Web.Blazor/Web.Blazor.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
1515
<PackageReference Include="Markdig" />
16-
<PackageReference Include="AWSSDK.S3" />
1716
<PackageReference Include="MediatR" />
1817
<PackageReference Include="Roslynator.Analyzers" PrivateAssets="all" />
1918
</ItemGroup>

src/Tests/AddonsDatabaseTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Common.Entities;
2+
using Minio;
3+
using Minio.DataModel.Args;
24
using System.Text;
35
using System.Text.Json;
46
using Xunit.Abstractions;
@@ -23,6 +25,7 @@ public async Task DatabaseFilesIntegrityTest()
2325
}
2426

2527
using HttpClient httpClient = new();
28+
2629
httpClient.DefaultRequestHeaders.Add("User-Agent", "BuildLauncher");
2730
httpClient.Timeout = TimeSpan.FromSeconds(30);
2831

@@ -58,4 +61,67 @@ public async Task DatabaseFilesIntegrityTest()
5861
_output.WriteLine(sb.ToString());
5962
Assert.True(sb.Length < 1);
6063
}
64+
65+
[Fact]
66+
public async Task LooseFilesTest()
67+
{
68+
if (!OperatingSystem.IsWindows())
69+
{
70+
return;
71+
}
72+
73+
var addonsJsonString = File.ReadAllText("../../../../db/addons.json");
74+
var addonsJson = JsonSerializer.Deserialize(addonsJsonString, DownloadableAddonsDictionaryContext.Default.DictionaryGameEnumListDownloadableAddonEntity);
75+
76+
Assert.NotNull(addonsJson);
77+
78+
79+
List<string>? addonsUrls = new List<string>();
80+
81+
foreach (var a in addonsJson.Values)
82+
{
83+
foreach (var b in a)
84+
{
85+
addonsUrls.Add(b.DownloadUrl.ToString());
86+
}
87+
}
88+
89+
var access = Environment.GetEnvironmentVariable("MINIO_ACCESS_KEY");
90+
var secret = Environment.GetEnvironmentVariable("MINIO_SECRET_KEY");
91+
92+
Assert.NotNull(access);
93+
Assert.NotNull(secret);
94+
95+
using var minio = new MinioClient()
96+
.WithEndpoint("s3.fgsfds.link:9000")
97+
.WithCredentials(access, secretKey: secret)
98+
.Build();
99+
100+
var args = new ListObjectsArgs()
101+
.WithBucket("buildlauncher")
102+
.WithRecursive(true);
103+
104+
var files = new List<string>();
105+
await foreach (var item in minio.ListObjectsEnumAsync(args))
106+
{
107+
if (item.Key.EndsWith('/'))
108+
{
109+
continue;
110+
}
111+
112+
files.Add("http://s3.fgsfds.link/buildlauncher/" + item.Key);
113+
}
114+
115+
var loose = files.Except(addonsUrls);
116+
117+
StringBuilder sb = new();
118+
119+
foreach (var item in loose)
120+
{
121+
_ = sb.AppendLine($"File {item} is loose.");
122+
}
123+
124+
_output.WriteLine(sb.ToString());
125+
Assert.True(sb.Length < 1);
126+
}
61127
}

src/Tests/Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>
2525
<PackageReference Include="Microsoft.NET.Test.Sdk" />
26+
<PackageReference Include="Minio" />
2627
<PackageReference Include="Moq" />
2728
<PackageReference Include="Roslynator.Analyzers" PrivateAssets="all" />
2829
<PackageReference Include="xunit" />

0 commit comments

Comments
 (0)