Skip to content

Commit

Permalink
Post updates (#2672)
Browse files Browse the repository at this point in the history
* Mark memory stream logger as public.

* Updates to assist in posting logs to endpoints.

* Update release notes.

* Update unit test return value processing.

* Update unit test return value processing.
  • Loading branch information
michaelcfanning committed May 16, 2023
1 parent fdec8a9 commit 441fa8b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SARIF Package Release History (SDK, Driver, Converters, and Multitool)
## **v4.2.0** UNRELEASED
* BRK: Update `SarifLog.Post(Uri, StreamWriter, HttpClient)` return value to `HttpResponseMessage` (to make returned correlation id and error messages available). [#2672](https://github.com/microsoft/sarif-sdk/pull/2672)
* BRK: `RuntimeConditions` now of type `long` to permit more flag values. Many literal values have changed for individual members. [#2660](https://github.com/microsoft/sarif-sdk/pull/2660)
* BRK: `RuntimeConditions.OneOrMoreFilesSkippedDueToSize` renamed to `OneOrMoreFilesSkippedDueToExceedingSizeLimits`. [#2660](https://github.com/microsoft/sarif-sdk/pull/2660)
* BRK: `Notes.LogFileSkippedDueToSize` renamed to `LogFileExceedingSizeLimitSkipped`. [#2660](https://github.com/microsoft/sarif-sdk/pull/2660)
Expand Down
7 changes: 2 additions & 5 deletions src/Sarif/Core/SarifLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static async Task Post(Uri postUri,
/// <param name="postUri"></param>
/// <param name="stream"></param>
/// <param name="httpClient"></param>
public static async Task Post(Uri postUri, Stream stream, HttpClient httpClient)
public static async Task<HttpResponseMessage> Post(Uri postUri, Stream stream, HttpClient httpClient)
{
if (postUri == null)
{
Expand All @@ -126,10 +126,7 @@ public static async Task Post(Uri postUri, Stream stream, HttpClient httpClient)
}

using var streamContent = new StreamContent(stream);
using HttpResponseMessage response = await httpClient
.PostAsync(postUri, streamContent);

response.EnsureSuccessStatusCode();
return await httpClient.PostAsync(postUri, streamContent);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Sarif/Writers/MemoryStreamSarifLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.CodeAnalysis.Sarif.Writers
{
internal class MemoryStreamSarifLogger : SarifLogger
public class MemoryStreamSarifLogger : SarifLogger
{
protected StreamWriter writer;
protected bool disposed;
Expand Down Expand Up @@ -37,7 +37,7 @@ public MemoryStreamSarifLogger(FilePersistenceOptions logFilePersistenceOptions
{
}

internal MemoryStreamSarifLogger(StreamWriter writer,
public MemoryStreamSarifLogger(StreamWriter writer,
FilePersistenceOptions logFilePersistenceOptions = FilePersistenceOptions.PrettyPrint,
OptionallyEmittedData dataToInsert = OptionallyEmittedData.None,
OptionallyEmittedData dataToRemove = OptionallyEmittedData.None,
Expand Down
11 changes: 7 additions & 4 deletions src/Test.UnitTests.Sarif/Core/SarifLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,14 @@ public async Task SarifLog_Post_BadRequestResponse()
new HttpRequestMessage(HttpMethod.Post, postUri) { Content = new StreamContent(CreateSarifLogStream()) },
HttpMockHelper.BadRequestResponse);

await Assert.ThrowsAsync<HttpRequestException>(async () =>
{
HttpResponseMessage response =
await SarifLog.Post(postUri,
CreateSarifLogStream(),
new HttpClient(httpMock));
CreateSarifLogStream(),
new HttpClient(httpMock));

Assert.Throws<HttpRequestException>(() =>
{
response.EnsureSuccessStatusCode();
});
}

Expand Down

0 comments on commit 441fa8b

Please sign in to comment.