[BUG]: RepositoryContentsClient.GetArchive does not return the expected binary content
Jericho opened this issue · comments
What happened?
This commit which was published in Octokit v8.1.1 introduced a change in HttpClientAdapter.cs
to return binary content as a stream rather than an array of byte. However, the code in RepositoryContentsClient.GetArchive still expects byte[]
and was not adjusted to handle a stream.
This problem was not caught in unit testing because none of the tests in RepositoryContentsClientTests
validate that GetArchive returns the expected array of bytes. I wrote the following unit test to demonstrate the problem. This unit test fails because the response does not contain the expected bytes:
[Fact]
public async Task ReturnsExpectedContent()
{
var headers = new Dictionary<string, string>();
var response = TestSetup.CreateResponse(HttpStatusCode.OK, new byte[] { 1, 2, 3, 4 }, headers);
var responseTask = Task.FromResult<IApiResponse<byte[]>>(new ApiResponse<byte[]>(response));
var connection = Substitute.For<IConnection>();
connection.Get<byte[]>(Arg.Is<Uri>(u => u.ToString() == "repos/org/repo/tarball/"), null)
.Returns(responseTask);
var apiConnection = Substitute.For<IApiConnection>();
apiConnection.Connection.Returns(connection);
var client = new RepositoryContentsClient(apiConnection);
var actual = await client.GetArchive("org", "repo");
Assert.Equal(new byte[] { 1, 2, 3, 4 }, actual); // <-- this assertion fails, thereby demonstrating that GetArchive does not return the expected array of bytes
}
I will submit a PR to resolve this problem and ensure that the unit test presented above completes successfully.
Versions
This problem can be observed in Octokit 8.1.1.
I verified 7.1.0, 7.2.0, 8.0.0 and 8.0.1 and they work fine. Meaning: they return the expected array of bytes.
Relevant log output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct