Skip to content

Commit

Permalink
Warnings6 (#829)
Browse files Browse the repository at this point in the history
* Fix warnings

* Fix warnings

* Fix regex

* Rewrite handlers

* Format

* Move files

* Format

* Remove

* Rename
  • Loading branch information
martijn00 authored Aug 9, 2023
1 parent 023ec7e commit fe3928a
Show file tree
Hide file tree
Showing 66 changed files with 298 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,5 @@ dotnet_separate_import_directive_groups = false

dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed

MA0051.maximum_lines_per_method = 100
MA0051.maximum_lines_per_method = 150
MA0051.maximum_statements_per_method = 60
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<!--
<PackageReference Include="Meziantou.Analyzer" Version="2.0.80">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.81">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.6">
<!--
<PackageReference Include="AsyncFixer" Version="1.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="AsyncFixer" Version="1.6.0">
<PackageReference Include="IDisposableAnalyzers" Version="4.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
1 change: 1 addition & 0 deletions Minio.Examples/Cases/MyRequestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System.Text;
using Minio.DataModel.Tracing;
using Minio.Handlers;

namespace Minio.Examples.Cases;

Expand Down
20 changes: 20 additions & 0 deletions Minio.Examples/Cases/RetryPolicyHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Minio.DataModel.Result;
using Minio.Handlers;
using Polly;

namespace Minio.Examples.Cases;

public class RetryPolicyHandler : IRetryPolicyHandler
{
private readonly AsyncPolicy<ResponseResult> policy;

public RetryPolicyHandler(AsyncPolicy<ResponseResult> policy)
{
this.policy = policy ?? throw new ArgumentNullException(nameof(policy));
}

public Task<ResponseResult> Handle(Func<Task<ResponseResult>> executeRequestCallback)
{
return policy.ExecuteAsync(executeRequestCallback);
}
}
10 changes: 6 additions & 4 deletions Minio.Examples/Cases/RetryPolicyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/

using Minio.DataModel.Result;
using Minio.Exceptions;
using Minio.Handlers;
using Polly;

namespace Minio.Examples.Cases;

internal static class RetryPolicyHelper
{
private const int defaultRetryCount = 3;
private const int DefaultRetryCount = 3;
private static readonly TimeSpan defaultRetryInterval = TimeSpan.FromMilliseconds(200);

private static readonly TimeSpan defaultMaxRetryInterval = TimeSpan.FromSeconds(10);
Expand Down Expand Up @@ -49,7 +51,7 @@ public static PolicyBuilder<ResponseResult> CreatePolicyBuilder()

public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy()
{
return GetDefaultRetryPolicy(defaultRetryCount, defaultRetryInterval, defaultMaxRetryInterval);
return GetDefaultRetryPolicy(DefaultRetryCount, defaultRetryInterval, defaultMaxRetryInterval);
}

public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy(
Expand All @@ -63,11 +65,11 @@ public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy(
i => CalcBackoff(i, retryInterval, maxRetryInterval));
}

public static RetryPolicyHandler AsRetryDelegate(this AsyncPolicy<ResponseResult> policy)
public static IRetryPolicyHandler AsRetryDelegate(this AsyncPolicy<ResponseResult> policy)
{
return policy is null
? null
: policy.ExecuteAsync;
: new RetryPolicyHandler(policy);
}

public static MinioClient WithRetryPolicy(this MinioClient client, AsyncPolicy<ResponseResult> policy)
Expand Down
4 changes: 3 additions & 1 deletion Minio.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -53,7 +54,8 @@ public static string GetRandomName()
return "minio-dotnet-example-" + result;
}

public static async Task Main(string[] args)
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs to run all tests")]
public static async Task Main()
{
string endPoint = null;
string accessKey = null;
Expand Down
60 changes: 31 additions & 29 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ internal static async Task ListBuckets_Test(MinioClient minio)
{
var list = await minio.ListBucketsAsync().ConfigureAwait(false);
bucketList = list.Buckets;
bucketList = bucketList.Where(x => x.Name.EndsWith(bucketNameSuffix)).ToList();
bucketList = bucketList.Where(x => x.Name.EndsWith(bucketNameSuffix, StringComparison.OrdinalIgnoreCase))
.ToList();
Assert.AreEqual(noOfBuckets, bucketList.Count);
bucketList.ToList().Sort((x, y) =>
{
Expand Down Expand Up @@ -729,7 +730,7 @@ internal static async Task PutGetStatEncryptedObject_Test1(MinioClient minio)
.WithObjectSize(filestream.Length)
.WithServerSideEncryption(ssec)
.WithContentType(contentType);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);

var getObjectArgs = new GetObjectArgs()
.WithBucket(bucketName)
Expand All @@ -752,8 +753,8 @@ internal static async Task PutGetStatEncryptedObject_Test1(MinioClient minio)
.WithBucket(bucketName)
.WithObject(objectName)
.WithServerSideEncryption(ssec);
await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
_ = await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
}

new MintLogger("PutGetStatEncryptedObject_Test1", putObjectSignature,
Expand Down Expand Up @@ -816,7 +817,7 @@ internal static async Task PutGetStatEncryptedObject_Test2(MinioClient minio)
.WithObjectSize(filestream.Length)
.WithContentType(contentType)
.WithServerSideEncryption(ssec);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);

var getObjectArgs = new GetObjectArgs()
.WithBucket(bucketName)
Expand All @@ -839,8 +840,8 @@ internal static async Task PutGetStatEncryptedObject_Test2(MinioClient minio)
.WithBucket(bucketName)
.WithObject(objectName)
.WithServerSideEncryption(ssec);
await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
_ = await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
}

new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
Expand Down Expand Up @@ -901,7 +902,7 @@ internal static async Task PutGetStatEncryptedObject_Test3(MinioClient minio)
.WithObjectSize(filestream.Length)
.WithServerSideEncryption(sses3)
.WithContentType(contentType);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);

var getObjectArgs = new GetObjectArgs()
.WithBucket(bucketName)
Expand All @@ -922,8 +923,8 @@ internal static async Task PutGetStatEncryptedObject_Test3(MinioClient minio)
var statObjectArgs = new StatObjectArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
_ = await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
}

new MintLogger("PutGetStatEncryptedObject_Test3", putObjectSignature,
Expand Down Expand Up @@ -1308,7 +1309,7 @@ internal static async Task DownloadObjectAsync(MinioClient minio, string url, st
{
using var response = await minio.WrapperGetAsync(url).ConfigureAwait(false);
if (string.IsNullOrEmpty(Convert.ToString(response.Content)) || !HttpStatusCode.OK.Equals(response.StatusCode))
throw new ArgumentNullException(nameof(response.Content), "Unable to download via presigned URL");
throw new InvalidOperationException("Unable to download via presigned URL" + nameof(response.Content));

using var fs = new FileStream(filePath, FileMode.CreateNew);
await response.Content.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -1340,7 +1341,9 @@ internal static async Task PresignedPostPolicy_Test1(MinioClient minio)
var args = new Dictionary<string, string>
(StringComparer.Ordinal)
{
{ "bucketName", bucketName }, { "objectName", objectName }, { "expiresOn", expiresOn.ToString() }
{ "bucketName", bucketName },
{ "objectName", objectName },
{ "expiresOn", expiresOn.ToString(CultureInfo.InvariantCulture) }
};

// File to be uploaded
Expand Down Expand Up @@ -2160,6 +2163,7 @@ internal static async Task ObjectVersioningAsync_Test1(MinioClient minio)

#region Object Lock Configuration

[SuppressMessage("Design", "MA0051:Method is too long", Justification = "TODO")]
internal static async Task ObjectLockConfigurationAsync_Test1(MinioClient minio)
{
var startTime = DateTime.Now;
Expand Down Expand Up @@ -2376,9 +2380,8 @@ internal static async Task ObjectRetentionAsync_Test1(MinioClient minio)
.WithRetentionUntilDate(untilDate);
await minio.SetObjectRetentionAsync(setRetentionArgs).ConfigureAwait(false);
new MintLogger(nameof(ObjectRetentionAsync_Test1), setObjectRetentionSignature,
"Tests whether SetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args)
.Log();
"Tests whether SetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args).Log();
}
catch (NotImplementedException ex)
{
Expand Down Expand Up @@ -2407,9 +2410,8 @@ internal static async Task ObjectRetentionAsync_Test1(MinioClient minio)
var untilDate = DateTime.Parse(config.RetainUntilDate, null, DateTimeStyles.RoundtripKind);
Assert.AreEqual(Math.Ceiling((untilDate - DateTime.Now).TotalDays), plusDays);
new MintLogger(nameof(ObjectRetentionAsync_Test1), getObjectRetentionSignature,
"Tests whether GetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args)
.Log();
"Tests whether GetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args).Log();
}
catch (NotImplementedException ex)
{
Expand Down Expand Up @@ -2809,8 +2811,8 @@ void Notify(MinioNotificationRaw data)
rxEventData = ev;
Notify(rxEventData);
},
ex => throw new ArgumentException($"OnError: {ex.Message}"),
() => throw new ArgumentException("STOPPED LISTENING FOR BUCKET NOTIFICATIONS\n"));
ex => throw new InvalidOperationException($"OnError: {ex.Message}"),
() => throw new InvalidOperationException("STOPPED LISTENING FOR BUCKET NOTIFICATIONS\n"));

// Sleep to give enough time for the subscriber to be ready
var sleepTime = 1000; // Milliseconds
Expand All @@ -2836,7 +2838,7 @@ void Notify(MinioNotificationRaw data)
{
await Task.Delay(waitTime).ConfigureAwait(false);
if ((DateTime.UtcNow - stTime).TotalMilliseconds >= timeout)
throw new ArgumentException("Timeout: while waiting for events");
throw new TimeoutException("Timeout: while waiting for events");
}

foreach (var ev in rxEventsList) Assert.AreEqual("s3:ObjectCreated:Put", ev.EventName);
Expand Down Expand Up @@ -2922,7 +2924,7 @@ internal static async Task ListenBucketNotificationsAsync_Test3(MinioClient mini
{
await Task.Delay(waitTime).ConfigureAwait(false);
if ((DateTime.UtcNow - stTime).TotalMilliseconds >= timeout)
throw new ArgumentException("Timeout: while waiting for events");
throw new TimeoutException("Timeout: while waiting for events");
}

if (!string.IsNullOrEmpty(rxEventData.json))
Expand All @@ -2941,7 +2943,7 @@ internal static async Task ListenBucketNotificationsAsync_Test3(MinioClient mini
}
else
{
throw new ArgumentException("Missed Event: Bucket notification failed.");
throw new InvalidDataException("Missed Event: Bucket notification failed.");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -4638,7 +4640,7 @@ internal static async Task GetObject_Test1(MinioClient minio)
.WithStreamData(filestream)
.WithObjectSize(filestream.Length)
.WithContentType(contentType);
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);

var getObjectArgs = new GetObjectArgs()
.WithBucket(bucketName)
Expand All @@ -4656,7 +4658,7 @@ internal static async Task GetObject_Test1(MinioClient minio)
Assert.AreEqual(file_write_size, file_read_size);
File.Delete(tempFileName);
});
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
}

await Task.Delay(1000).ConfigureAwait(false);
Expand Down Expand Up @@ -5236,7 +5238,7 @@ internal static async Task ListObjects_Test6(MinioClient minio)
var subscription = observable.Subscribe(
item =>
{
Assert.IsTrue(item.Key.StartsWith(objectNamePrefix));
Assert.IsTrue(item.Key.StartsWith(objectNamePrefix, StringComparison.OrdinalIgnoreCase));
if (!objectNamesSet.Add(item.Key))
new MintLogger("ListObjects_Test6", listObjectsSignature,
"Tests whether ListObjects lists more than 1000 objects correctly(max-keys = 1000)",
Expand Down Expand Up @@ -5309,7 +5311,7 @@ internal static async Task ListObjectVersions_Test1(MinioClient minio)
var subscription = observable.Subscribe(
item =>
{
Assert.IsTrue(item.Key.StartsWith(prefix));
Assert.IsTrue(item.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
count++;
objectVersions.Add(new Tuple<string, string>(item.Key, item.VersionId));
},
Expand Down Expand Up @@ -5526,7 +5528,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio)
"reqParams",
"response-content-type:application/json,response-content-disposition:attachment;filename= MyDoc u m e nt.json ;"
},
{ "reqDate", reqDate.ToString() }
{ "reqDate", reqDate.ToString(CultureInfo.InvariantCulture) }
};
try
{
Expand Down Expand Up @@ -5562,7 +5564,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio)

using var response = await minio.WrapperGetAsync(presigned_url).ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(Convert.ToString(response.Content)))
throw new ArgumentNullException(nameof(response.Content), "Unable to download via presigned URL");
throw new InvalidOperationException("Unable to download via presigned URL " + nameof(response.Content));

Assert.IsTrue(response.Content.Headers.GetValues("Content-Type")
.Contains(reqParams["response-content-type"], StringComparer.Ordinal));
Expand Down
1 change: 1 addition & 0 deletions Minio.Functional.Tests/JsonNetLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System.Text.Json;
using Minio.DataModel.Tracing;
using Minio.Handlers;

namespace Minio.Functional.Tests;

Expand Down
6 changes: 4 additions & 2 deletions Minio.Functional.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using Minio.Helper;
Expand All @@ -24,6 +25,7 @@ namespace Minio.Functional.Tests;

internal static class Program
{
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs to run all tests")]
public static async Task Main(string[] args)
{
string endPoint = null;
Expand All @@ -40,7 +42,7 @@ public static async Task Main(string[] args)
var posColon = endPoint.LastIndexOf(':');
if (posColon != -1)
{
port = int.Parse(endPoint.Substring(posColon + 1, endPoint.Length - posColon - 1), NumberStyles.Integer,
port = int.Parse(endPoint.AsSpan(posColon + 1, endPoint.Length - posColon - 1), NumberStyles.Integer,
CultureInfo.InvariantCulture);
endPoint = endPoint[..posColon];
}
Expand Down Expand Up @@ -110,7 +112,7 @@ public static async Task Main(string[] args)
// If the following test is run against AWS, then the SDK throws
// "Listening for bucket notification is specific only to `minio`
// server endpoints".
await FunctionalTest.ListenBucketNotificationsAsync_Test1(minioClient);
await FunctionalTest.ListenBucketNotificationsAsync_Test1(minioClient).ConfigureAwait(false);
functionalTestTasks.Add(FunctionalTest.ListenBucketNotificationsAsync_Test2(minioClient));
functionalTestTasks.Add(FunctionalTest.ListenBucketNotificationsAsync_Test3(minioClient));

Expand Down
3 changes: 2 additions & 1 deletion Minio.Tests/RegionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Minio.Helper;

namespace Minio.Tests;

Expand All @@ -37,6 +38,6 @@ public class RegionTest
[DataRow("localhost:9000", "")]
public void TestGetRegion(string endpoint, string expectedRegion)
{
Assert.AreEqual(expectedRegion, Regions.GetRegionFromEndpoint(endpoint));
Assert.AreEqual(expectedRegion, RegionHelper.GetRegionFromEndpoint(endpoint));
}
}
4 changes: 2 additions & 2 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ public IObservable<MinioNotificationRaw> ListenBucketNotificationsAsync(ListenBu
{
if (S3utils.IsAmazonEndPoint(BaseUrl))
// Amazon AWS does not support bucket notifications
throw new ArgumentException(
"Listening for bucket notification is specific only to `minio` server endpoints", nameof(BaseUrl));
throw new ConnectionException(
"Listening for bucket notification is specific only to `minio` server endpoints");

return Observable.Create<MinioNotificationRaw>(
async (obs, ct) =>
Expand Down
Loading

0 comments on commit fe3928a

Please sign in to comment.