Files

111 lines
3.8 KiB
C#
Raw Permalink Normal View History

2023-12-17 17:00:38 +00:00
using System.CommandLine;
2024-03-27 20:50:53 +00:00
using Velopack.Vpk.Commands.Deployment;
2023-12-17 17:00:38 +00:00
2023-12-31 11:09:44 +00:00
namespace Velopack.CommandLine.Tests.Commands;
2022-09-24 00:05:25 -07:00
2023-12-15 17:27:33 +00:00
public abstract class S3CommandTests<T> : BaseCommandTests<T>
where T : S3BaseCommand, new()
2022-09-24 00:05:25 -07:00
{
2023-12-15 17:27:33 +00:00
[Fact]
public void Command_WithRequiredEndpointOptions_ParsesValue()
2022-09-24 00:05:25 -07:00
{
2023-12-15 17:27:33 +00:00
S3BaseCommand command = new T();
2022-09-24 00:05:25 -07:00
2023-12-15 17:27:33 +00:00
string cli = $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
2022-09-24 00:05:25 -07:00
2023-12-15 17:27:33 +00:00
Assert.Empty(parseResult.Errors);
Assert.Equal("some key", command.KeyId);
Assert.Equal("shhhh", command.Secret);
Assert.Equal("http://endpoint/", command.Endpoint);
2024-03-28 09:43:27 +00:00
Assert.Equal("a-bucket", command.Bucket);
2022-09-24 00:05:25 -07:00
}
2022-12-05 12:01:00 +00:00
2023-12-15 17:27:33 +00:00
[Fact]
public void Command_WithRequiredRegionOptions_ParsesValue()
2022-12-05 12:01:00 +00:00
{
2023-12-15 17:27:33 +00:00
S3BaseCommand command = new T();
2022-12-05 14:12:15 +00:00
2023-12-15 17:27:33 +00:00
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
2022-12-05 12:01:00 +00:00
2023-12-15 17:27:33 +00:00
Assert.Empty(parseResult.Errors);
Assert.Equal("some key", command.KeyId);
Assert.Equal("shhhh", command.Secret);
Assert.Equal("us-west-1", command.Region);
2024-03-28 09:43:27 +00:00
Assert.Equal("a-bucket", command.Bucket);
2023-12-15 17:27:33 +00:00
}
2022-12-05 12:01:00 +00:00
2023-12-15 17:27:33 +00:00
[Fact]
public void Command_WithoutRegionArgumentValue_ShowsError()
{
S3BaseCommand command = new T();
2022-12-05 12:01:00 +00:00
2023-12-15 17:27:33 +00:00
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\" --region \"\"";
ParseResult parseResult = command.ParseAndApply(cli);
2022-12-05 12:01:00 +00:00
2023-12-15 17:27:33 +00:00
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Region, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("A region value is required", parseResult.Errors[0].Message);
}
2022-12-05 12:01:00 +00:00
2023-12-15 17:27:33 +00:00
[Fact]
public void Command_WithoutRegionAndEndpoint_ShowsError()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.StartsWith("At least one of the following options are required '--region' and '--endpoint'", parseResult.Errors[0].Message);
}
[Fact]
public void Command_WithBothRegionAndEndpoint_ShowsError()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.StartsWith("Cannot use '--region' and '--endpoint' options together", parseResult.Errors[0].Message);
}
2024-01-03 16:24:41 +00:00
//[Fact]
//public void PathPrefix_WithPath_ParsesValue()
//{
// S3BaseCommand command = new T();
2023-12-15 17:27:33 +00:00
2024-01-03 16:24:41 +00:00
// string cli = GetRequiredDefaultOptions() + $"--pathPrefix \"sub-folder\"";
// ParseResult parseResult = command.ParseAndApply(cli);
2023-12-15 17:27:33 +00:00
2024-01-03 16:24:41 +00:00
// Assert.Equal("sub-folder", command.PathPrefix);
//}
2023-12-15 17:27:33 +00:00
protected override string GetRequiredDefaultOptions()
{
return $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\" ";
}
}
public class S3DownloadCommandTests : S3CommandTests<S3DownloadCommand>
{ }
public class S3UploadCommandTests : S3CommandTests<S3UploadCommand>
{
public override bool ShouldBeNonEmptyReleaseDir => true;
2024-01-03 16:24:41 +00:00
//[Fact]
//public void KeepMaxReleases_WithNumber_ParsesValue()
//{
// var command = new S3UploadCommand();
2023-12-15 17:27:33 +00:00
2024-01-03 16:24:41 +00:00
// string cli = GetRequiredDefaultOptions() + "--keepMaxReleases 42";
// ParseResult parseResult = command.ParseAndApply(cli);
2023-12-15 17:27:33 +00:00
2024-01-03 16:24:41 +00:00
// Assert.Equal(42, command.KeepMaxReleases);
//}
2022-09-24 00:05:25 -07:00
}