Add --timeout as a cli option

This commit is contained in:
Ben Evans
2024-11-28 23:34:48 +00:00
committed by Caelan
parent c03a960a25
commit ea0a6ce8b7
17 changed files with 92 additions and 28 deletions

View File

@@ -17,7 +17,7 @@ public class OptionMapperTests
public void MapCommand()
{
AzureUploadCommand command = new();
string cli = $"--account \"account-name\" --key \"shhhh\" --endpoint \"https://endpoint\" --container \"mycontainer\"";
string cli = $"--account \"account-name\" --key \"shhhh\" --endpoint \"https://endpoint\" --container \"mycontainer\" --timeout 45";
ParseResult parseResult = command.ParseAndApply(cli);
var options = OptionMapper.Map<AzureUploadOptions>(command);
@@ -26,5 +26,6 @@ public class OptionMapperTests
Assert.Equal("shhhh", options.Key);
Assert.Equal("https://endpoint/", options.Endpoint);
Assert.Equal("mycontainer", options.Container);
Assert.Equal(45, options.Timeout);
}
}

View File

@@ -11,7 +11,7 @@ public class FakeDownloader : Sources.IFileDownloader
public byte[] MockedResponseBytes { get; set; } = new byte[0];
public bool WriteMockLocalFile { get; set; } = false;
public Task<byte[]> DownloadBytes(string url, string auth, string acc)
public Task<byte[]> DownloadBytes(string url, string auth, string acc, double timeout = 30)
{
LastUrl = url;
LastAuthHeader = auth;
@@ -19,7 +19,7 @@ public class FakeDownloader : Sources.IFileDownloader
return Task.FromResult(MockedResponseBytes);
}
public async Task DownloadFile(string url, string targetFile, Action<int> progress, string auth, string acc, CancellationToken token)
public async Task DownloadFile(string url, string targetFile, Action<int> progress, string auth, string acc, double timeout, CancellationToken token)
{
LastLocalFile = targetFile;
var resp = await DownloadBytes(url, auth, acc);
@@ -31,7 +31,7 @@ public class FakeDownloader : Sources.IFileDownloader
File.WriteAllBytes(targetFile, resp);
}
public async Task<string> DownloadString(string url, string auth, string acc)
public async Task<string> DownloadString(string url, string auth, string acc, double timeout = 30)
{
return Encoding.UTF8.GetString(await DownloadBytes(url, auth, acc));
}

View File

@@ -55,7 +55,7 @@ internal class FakeFixtureRepository : Sources.IFileDownloader
_releases = releases;
}
public Task<byte[]> DownloadBytes(string url, string authorization = null, string accept = null)
public Task<byte[]> DownloadBytes(string url, string authorization = null, string accept = null, double timeout = 30)
{
if (url.Contains($"/{_releasesName}?")) {
MemoryStream ms = new MemoryStream();
@@ -80,7 +80,7 @@ internal class FakeFixtureRepository : Sources.IFileDownloader
return Task.FromResult(File.ReadAllBytes(filePath));
}
public Task DownloadFile(string url, string targetFile, Action<int> progress, string authorization = null, string accept = null, CancellationToken token = default)
public Task DownloadFile(string url, string targetFile, Action<int> progress, string authorization = null, string accept = null, double timeout = 30, CancellationToken token = default)
{
var rel = _releases.FirstOrDefault(r => url.EndsWith(r.OriginalFilename));
var filePath = PathHelper.GetFixture(rel.OriginalFilename);
@@ -96,7 +96,7 @@ internal class FakeFixtureRepository : Sources.IFileDownloader
return Task.CompletedTask;
}
public Task<string> DownloadString(string url, string authorization = null, string accept = null)
public Task<string> DownloadString(string url, string authorization = null, string accept = null, double timeout = 30)
{
if (url.Contains($"/{_releasesName}?")) {
MemoryStream ms = new MemoryStream();