Skip to content

Commit

Permalink
Builder refactoring including WithBucket. (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
BigUstad authored Sep 9, 2020
1 parent b780b0d commit d49910c
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 76 deletions.
3 changes: 2 additions & 1 deletion Minio.Examples/Cases/BucketExists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public async static Task Run(MinioClient minio,
try
{
Console.WriteLine("Running example for API: BucketExistsAsync");
BucketExistsArgs args = new BucketExistsArgs(bucketName);
BucketExistsArgs args = new BucketExistsArgs()
.WithBucket(bucketName);
bool found = await minio.BucketExistsAsync(args);
Console.WriteLine((found ? "Found" : "Couldn't find ") + "bucket " + bucketName);
Console.WriteLine();
Expand Down
4 changes: 2 additions & 2 deletions Minio.Examples/Cases/EnableSuspendVersioning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

using System;
using System.Threading.Tasks;
using Minio.DataModel;

namespace Minio.Examples.Cases
{
Expand All @@ -30,7 +29,8 @@ public async static Task Run(MinioClient minio,
{
Console.WriteLine("Running example for API: EnableSuspendVersioning, ");
// First Enable the Versioning.
var setArgs = new SetVersioningArgs(bucketName)
var setArgs = new SetVersioningArgs()
.WithBucket(bucketName)
.WithVersioningEnabled();
await minio.SetVersioningAsync(setArgs);
Console.WriteLine("Versioning Enable operation called for bucket " + bucketName);
Expand Down
5 changes: 3 additions & 2 deletions Minio.Examples/Cases/GetVersioning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class GetVersioning
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name")
{
var args = new GetVersioningArgs(bucketName);
var args = new GetVersioningArgs()
.WithBucket(bucketName);

try
{
Console.WriteLine("Running example for API: GetVersioning, ");
VersioningConfiguration config = await minio.GetVersioningAsync(args);
if ( config == null )
if (config == null)
{
Console.WriteLine("Versioning Configuration not available for bucket " + bucketName);
Console.WriteLine();
Expand Down
5 changes: 3 additions & 2 deletions Minio.Examples/Cases/MakeBucket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017-2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,8 @@ public async static Task Run(MinioClient minio,
{
Console.WriteLine("Running example for API: MakeBucketAsync");
await minio.MakeBucketAsync(
new MakeBucketArgs(bucketName)
new MakeBucketArgs()
.WithBucket(bucketName)
.WithLocation(loc)
);
Console.WriteLine($"Created bucket {bucketName}");
Expand Down
46 changes: 46 additions & 0 deletions Minio.Examples/Cases/MakeBucketWithLock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* 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 System.Threading.Tasks;

namespace Minio.Examples.Cases
{
public class MakeBucketWithLock
{
// Make a bucket
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name", string loc = "us-east-1")
{
try
{
Console.WriteLine("Running example for API: MakeBucketAsync");
await minio.MakeBucketAsync(
new MakeBucketArgs()
.WithBucket(bucketName)
.WithLocation(loc)
.WithObjectLock()
);
Console.WriteLine($"Created bucket {bucketName} with lock.");
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine($"[Bucket] Exception: {e}");
}
}
}
}
3 changes: 2 additions & 1 deletion Minio.Examples/Cases/RemoveBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public async static Task Run(MinioClient minio,
try
{
await minio.RemoveBucketAsync(
new RemoveBucketArgs(bucketName)
new RemoveBucketArgs()
.WithBucket(bucketName)
);
Console.WriteLine($"Removed the bucket {bucketName} successfully");
}
Expand Down
12 changes: 9 additions & 3 deletions Minio.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void Main(string[] args)
{
endPoint = Environment.GetEnvironmentVariable("SERVER_ENDPOINT");
int posColon = endPoint.LastIndexOf(':');
if ( posColon != -1 )
if (posColon != -1)
{
port = Int32.Parse(endPoint.Substring(posColon+1, (endPoint.Length - posColon - 1)));
endPoint = endPoint.Substring(0, posColon);
Expand All @@ -76,7 +76,7 @@ public static void Main(string[] args)
if (Environment.GetEnvironmentVariable("ENABLE_HTTPS") != null)
{
enableHTTPS = Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1");
if ( enableHTTPS && port == 80 )
if (enableHTTPS && port == 80)
{
port = 443;
}
Expand All @@ -96,7 +96,7 @@ public static void Main(string[] args)

// WithSSL() enables SSL support in MinIO client
MinioClient minioClient = null;
if ( enableHTTPS )
if (enableHTTPS)
{
minioClient = new MinioClient()
.WithEndpoint(endPoint, port)
Expand All @@ -120,6 +120,7 @@ public static void Main(string[] args)
string objectName = GetRandomName();
string destBucketName = GetRandomName();
string destObjectName = GetRandomName();
string lockBucketName = GetRandomName();
List<string> objectsList = new List<string>();
for (int i = 0; i < 10; i++)
{
Expand All @@ -141,6 +142,11 @@ public static void Main(string[] args)

Cases.MakeBucket.Run(minioClient, destBucketName).Wait();

// Bucket with Lock tests
Cases.MakeBucketWithLock.Run(minioClient, lockBucketName).Wait();
Cases.BucketExists.Run(minioClient, lockBucketName).Wait();
Cases.RemoveBucket.Run(minioClient, lockBucketName).Wait();

//Versioning tests
Cases.GetVersioning.Run(minioClient, bucketName).Wait();
Cases.EnableSuspendVersioning.Run(minioClient, bucketName).Wait();
Expand Down
97 changes: 75 additions & 22 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ internal async static Task BucketExists_Test(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName();
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand All @@ -197,9 +200,12 @@ internal async static Task MakeBucket_Test1(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(length: 60);
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand All @@ -224,9 +230,12 @@ internal async static Task MakeBucket_Test2(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(length: 10) + ".withperiod";
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand Down Expand Up @@ -254,10 +263,13 @@ internal async static Task MakeBucket_Test3(MinioClient minio, bool aws = false)
return;
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(length: 60);
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName)
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName)
.WithLocation("eu-central-1");
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand Down Expand Up @@ -290,10 +302,13 @@ internal async static Task MakeBucket_Test4(MinioClient minio, bool aws = false)
return;
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(length: 20) + ".withperiod";
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName)
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName)
.WithLocation("us-west-2");
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand Down Expand Up @@ -329,7 +344,8 @@ internal async static Task MakeBucket_Test5(MinioClient minio)
try
{
await Assert.ThrowsExceptionAsync<InvalidBucketNameException>(() =>
minio.MakeBucketAsync(new MakeBucketArgs(bucketName)));
minio.MakeBucketAsync(new MakeBucketArgs()
.WithBucket(bucketName)));
new MintLogger(nameof(MakeBucket_Test5), makeBucketSignature, "Tests whether MakeBucket throws InvalidBucketNameException when bucketName is null", TestStatus.PASS, (DateTime.Now - startTime), args: args).Log();
}
catch (MinioException ex)
Expand All @@ -338,15 +354,49 @@ await Assert.ThrowsExceptionAsync<InvalidBucketNameException>(() =>
}
}

internal async static Task MakeBucketLock_Test1(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(length: 60);
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName)
.WithObjectLock();
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
{ "region", "us-east-1" },
};

try
{
await minio.MakeBucketAsync(mbArgs);
bool found = await minio.BucketExistsAsync(beArgs);
Assert.IsTrue(found);
await minio.RemoveBucketAsync(rbArgs);
new MintLogger(nameof(MakeBucket_Test1), makeBucketSignature, "Tests whether MakeBucket with Lock passes", TestStatus.PASS, (DateTime.Now - startTime), args:args).Log();
}
catch (MinioException ex)
{
new MintLogger(nameof(MakeBucket_Test1), makeBucketSignature, "Tests whether MakeBucket with Lock passes", TestStatus.FAIL, (DateTime.Now - startTime), "", ex.Message, ex.ToString(), args).Log();
}
}

#endregion

internal async static Task RemoveBucket_Test1(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(length: 20);
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
Expand Down Expand Up @@ -390,16 +440,19 @@ internal async static Task ListBuckets_Test(MinioClient minio)

internal async static Task Setup_Test(MinioClient minio, string bucketName)
{
MakeBucketArgs mbArgs = new MakeBucketArgs(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs(bucketName);
MakeBucketArgs mbArgs = new MakeBucketArgs()
.WithBucket(bucketName);
BucketExistsArgs beArgs = new BucketExistsArgs()
.WithBucket(bucketName);
await minio.MakeBucketAsync(mbArgs);
bool found = await minio.BucketExistsAsync(beArgs);
Assert.IsTrue(found);
}

internal async static Task TearDown(MinioClient minio, string bucketName)
{
RemoveBucketArgs rbArgs = new RemoveBucketArgs(bucketName);
RemoveBucketArgs rbArgs = new RemoveBucketArgs()
.WithBucket(bucketName);
await minio.RemoveBucketAsync(rbArgs);
}

Expand Down
Loading

0 comments on commit d49910c

Please sign in to comment.