Skip to content

Commit

Permalink
fix(dotnet#578): Add ChunkedReadStream write operations
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Aug 18, 2022
1 parent 6285c9a commit 0e39560
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Docker.DotNet/Microsoft.Net.Http.Client/ChunkedReadStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public override bool CanWrite
get { return false; }
}

public override bool CanCloseWrite
{
get { return _inner.CanCloseWrite; }
}

public override long Length
{
get { throw new NotSupportedException(); }
Expand Down Expand Up @@ -154,12 +159,12 @@ private void ThrowIfDisposed()

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
_inner.Write(buffer, offset, count);
}

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
throw new NotSupportedException();
return _inner.WriteAsync(buffer, offset, count, cancellationToken);
}

public override long Seek(long offset, SeekOrigin origin)
Expand All @@ -174,12 +179,9 @@ public override void SetLength(long value)

public override void Flush()
{
throw new NotSupportedException();
_inner.Flush();
}

public override bool CanCloseWrite
=> _inner.CanCloseWrite;

public override void CloseWrite()
{
_inner.CloseWrite();
Expand Down
40 changes: 40 additions & 0 deletions test/Docker.DotNet.Tests/IContainerOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet.Models;
Expand Down Expand Up @@ -820,5 +821,44 @@ public async Task CreateImageAsync_NonexistantImage_ThrowsDockerImageNotFoundExc

await Assert.ThrowsAsync<DockerImageNotFoundException>(op);
}

[Fact]
public async Task MultiplexedStreamWriteAsync_DoesNotThrowAnException()
{
// Given
Exception exception;

var createContainerResponse = await _dockerClient.Containers.CreateContainerAsync(
new CreateContainerParameters
{
Image = _imageId
})
.ConfigureAwait(false);

_ = await _dockerClient.Containers.StartContainerAsync(createContainerResponse.ID, new ContainerStartParameters())
.ConfigureAwait(false);

var containerExecCreateResponse = await _dockerClient.Exec.ExecCreateContainerAsync(createContainerResponse.ID,
new ContainerExecCreateParameters
{
AttachStdout = true,
AttachStderr = true,
AttachStdin = true,
Cmd = new [] { string.Empty }
})
.ConfigureAwait(false);

// When
using (var stream = await _dockerClient.Exec.StartAndAttachContainerExecAsync(containerExecCreateResponse.ID, false)
.ConfigureAwait(false))
{
var buffer = Encoding.ASCII.GetBytes("\n");
exception = await Record.ExceptionAsync(() => stream.WriteAsync(buffer, 0, buffer.Length, default))
.ConfigureAwait(false);
}

// Then
Assert.Null(exception);
}
}
}

0 comments on commit 0e39560

Please sign in to comment.