Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 37 additions & 18 deletions src/Storage.Tests/ObjectShould.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Net;
using System.Net;
using static Storage.Tests.StorageFixture;

namespace Storage.Tests;
Expand All @@ -8,8 +8,8 @@
private readonly S3Client _client;
private readonly CancellationToken _ct;
private readonly StorageFixture _fixture;
private readonly S3Client _notExistsBucketClient; // don't dispose it

private readonly S3Client _notExistsBucketClient; // don't dispose it
public ObjectShould(StorageFixture fixture)
{
_ct = CancellationToken.None;
Expand Down Expand Up @@ -71,7 +71,7 @@
.Should().BeTrue();

task
.Result

Check warning on line 74 in src/Storage.Tests/ObjectShould.cs

View workflow job for this annotation

GitHub Actions / build

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 74 in src/Storage.Tests/ObjectShould.cs

View workflow job for this annotation

GitHub Actions / build

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)
.Should().BeTrue();

task.Dispose();
Expand Down Expand Up @@ -136,9 +136,9 @@
public async Task DisposeStorageFile()
{
var fileName = await CreateTestFile();
using var fileGetResult = await _client.GetFile(fileName, _ct);

// ReSharper disable once DisposeOnUsingVariable
using var fileGetResult = await _client.GetFile(fileName, _ct);
// ReSharper disable once DisposeOnUsingVariable
fileGetResult.Dispose();

await DeleteTestFile(fileName);
Expand Down Expand Up @@ -370,28 +370,28 @@

var buffer = new byte[1024];
var file = await _client.GetFile(fileName, _ct);
var fileStream = await file.GetStream(_ct);

var fileStream = await file.GetStream(_ct);
#pragma warning disable CA1835
var read = await fileStream.ReadAsync(buffer, _ct);
read.Should().BeGreaterThan(0);

read = await fileStream.ReadAsync(buffer, 10, 20, _ct);
read.Should().BeGreaterThan(0);

// ReSharper disable once MethodHasAsyncOverloadWithCancellation
read.Should().BeGreaterThan(0);
// ReSharper disable once MethodHasAsyncOverloadWithCancellation
read = fileStream.Read(buffer, 10, 20);
read.Should().BeGreaterThan(0);
read.Should().BeGreaterThan(0);
#pragma warning restore CA1835

await DeleteTestFile(fileName);
}

[Fact]
public async Task Upload()
{
var fileName = _fixture.Create<string>();
using var data = GetByteStream(12 * 1024 * 1024); // 12 Mb
using var data = GetByteStream(12 * 1024 * 1024); // 12 Mb
var filePutResult = await _client.UploadFile(fileName, StreamContentType, data, _ct);

filePutResult
Expand Down Expand Up @@ -505,8 +505,27 @@
await _notExistsBucketClient
.Invoking(client => client.UploadFile(fileName, StreamContentType, fileArray, _ct))
.Should().ThrowAsync<HttpRequestException>();
}

[Theory]
[InlineData("some/foo/audio.wav", 1024)]
[InlineData("another/path/test.mp3", 2048)]
public async Task UploadFileWithNestedPath(string nestedFileName, int dataSize)
{
var data = GetByteArray(dataSize); // Пример данных, которые вы хотите загрузить

// Act
var result = await _client.UploadFile(nestedFileName, StreamContentType, data, _ct);
Assert.True(result);

// Assert
var exists = await _client.IsFileExists(nestedFileName, _ct);
Assert.True(exists, "The object should exist in the S3 bucket");

await DeleteTestFile(nestedFileName);
}

Check warning on line 527 in src/Storage.Tests/ObjectShould.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 527 in src/Storage.Tests/ObjectShould.cs

View workflow job for this annotation

GitHub Actions / build


[Fact]
public async Task ThrowIfUploadDisposed()
{
Expand Down Expand Up @@ -534,8 +553,8 @@
int? size = null)
{
fileName ??= _fixture.Create<string>();
using var data = GetByteStream(size ?? 1 * 1024 * 1024); // 1 Mb

using var data = GetByteStream(size ?? 1 * 1024 * 1024); // 1 Mb
var uploadResult = await _client.UploadFile(fileName, contentType, data, _ct);

uploadResult
Expand Down Expand Up @@ -570,8 +589,8 @@
memoryStream
.ToArray().SequenceEqual(expectedBytes.ToArray())
.Should().BeTrue();
}

}
private Task DeleteTestFile(string fileName)
{
return _client.DeleteFile(fileName, _ct);
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/Utils/HttpDescription.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Buffers;
using System.Buffers;
using System.Collections.Frozen;
using System.Text;

Expand All @@ -7,7 +7,7 @@ namespace Storage.Utils;
internal readonly struct HttpDescription
{
private static readonly FrozenSet<char> _validUrlCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~".ToFrozenSet();
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~/".ToFrozenSet();

private readonly string _headerEnd;
private readonly string _headerStart;
Expand Down
6 changes: 3 additions & 3 deletions src/Storage/Utils/ValueStringBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Buffers;
using System.Buffers;
using System.Globalization;

namespace Storage.Utils;

internal ref struct ValueStringBuilder(Span<char> buffer)
internal ref struct ValueStringBuilder(Span<char> initialBuffer)
{
private Span<char> _buffer = buffer;
private Span<char> _buffer = initialBuffer;
private int _length = 0;
private char[]? _array = null;

Expand Down