Skip to content

Commit

Permalink
Merge branch 'log-params-customize'
Browse files Browse the repository at this point in the history
  • Loading branch information
patrofimov committed Sep 3, 2024
2 parents 0dcd9de + adf8854 commit 991c469
Show file tree
Hide file tree
Showing 17 changed files with 823 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.55 (03-09-2024):

Added more options for loggin request/response query string and headers.

## 0.1.54 (27-08-2024):

Don't validate stream content if retry is not needed
Expand Down
61 changes: 56 additions & 5 deletions Vostok.ClusterClient.Core.Tests/Model/Request_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,33 @@ public void ToString_should_return_correct_value_when_printing_both_query_and_he
{
request = request.WithHeader("name", "value");

request.ToString(true, true).Should().Be("POST http://foo/bar?a=b" + Environment.NewLine + "name: value");
request.ToString(true, true).Should().Be("POST http://foo/bar?a=b" + Environment.NewLine + "name=value");
}

[TestCase("foo/bar?a=b", "POST foo/bar?a=b")]
[TestCase("foo/bar", "POST foo/bar")]
public void ToString_should_return_correct_value_for_relative_url_with_query(string input, string expected)
{
request = new Request(RequestMethods.Post, new Uri(input, UriKind.Relative), Content.Empty, Headers.Empty);

request.ToString(true, false).Should().Be(expected);
}

[TestCase("foo/bar?a=b", "POST foo/bar")]
[TestCase("foo/bar", "POST foo/bar")]
public void ToString_should_return_correct_value_for_relative_url_without_query(string input, string expected)
{
request = new Request(RequestMethods.Post, new Uri(input, UriKind.Relative), Content.Empty, Headers.Empty);

request.ToString(false, false).Should().Be(expected);
}

[Test]
public void ToString_should_return_correct_value_when_printing_headers_but_omitting_query()
{
request = request.WithHeader("name", "value");

request.ToString(false, true).Should().Be("POST http://foo/bar" + Environment.NewLine + "name: value");
request.ToString(false, true).Should().Be("POST http://foo/bar" + Environment.NewLine + "name=value");
}

[Test]
Expand All @@ -652,10 +670,43 @@ public void ToString_should_omit_query_and_headers_by_default()
request.ToString().Should().Be("POST http://foo/bar");
}

[Test]
public void ToString_should_print_headers_single_line()
{
request = request.WithHeader("name1", "value1").WithHeader("name2", "value2");

request.ToString(false, true, true).Should().Be("POST http://foo/bar Headers: (name1=value1, name2=value2)");
}

[Test]
public void ToString_should_print_headers()
{
request = request.WithHeader("name1", "value1").WithHeader("name2", "value2");

request.ToString(false, true).Should().Be("POST http://foo/bar\r\nname1=value1\r\nname2=value2");
}

[Test]
public void ToString_should_print_query_and_headers_single_line()
{
request = request.WithHeader("name1", "value1").WithHeader("name2", "value2");

request.ToString(true, true, true).Should().Be("POST http://foo/bar?a=b Headers: (name1=value1, name2=value2)");
}

[Test]
public void ToString_should_tolerate_empty_headers()
{
request.ToString(true, true).Should().Be("POST http://foo/bar?a=b");
request.ToString(true, true, true).Should().Be("POST http://foo/bar?a=b");
}

[Test]
public void ToString_should_tolerate_empty_query()
{
request = new Request(RequestMethods.Post, new Uri("http://foo/bar"), Content.Empty, Headers.Empty);
request.ToString(true, true).Should().Be("POST http://foo/bar");
request.ToString(true, true, true).Should().Be("POST http://foo/bar");
}

[Test]
Expand Down Expand Up @@ -736,13 +787,13 @@ public void TryGetQueryParameter_should_work()
{
request = request.WithAdditionalQueryParameter("abc", "123");
request = request.WithAdditionalQueryParameter("x", "1?=&2");

request.TryGetQueryParameter("abc", out var value).Should().BeTrue();
value.Should().Be("123");

request.TryGetQueryParameter("x", out value).Should().BeTrue();
value.Should().Be("1?=&2");

request.TryGetQueryParameter("y", out value).Should().BeFalse();
}
}
Expand Down
20 changes: 19 additions & 1 deletion Vostok.ClusterClient.Core.Tests/Model/Response_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,23 @@ public void ToString_should_return_correct_representation_when_printing_headers(
{
var response = new Response(ResponseCode.Ok, headers: Headers.Empty.Set("name", "value"));

response.ToString(true).Should().Be("200 Ok" + Environment.NewLine + "name: value");
response.ToString(true).Should().Be("200 Ok" + Environment.NewLine + "name=value");
}

[Test]
public void ToString_should_print_headers_single_line()
{
var response = new Response(ResponseCode.Ok, headers: Headers.Empty.Set("name1", "value1").Set("name2", "value2"));

response.ToString(true, true).Should().Be("200 Ok Headers: (name1=value1, name2=value2)");
}

[Test]
public void ToString_should_print_headers()
{
var response = new Response(ResponseCode.Ok, headers: Headers.Empty.Set("name1", "value1").Set("name2", "value2"));

response.ToString(true).Should().Be("200 Ok\r\nname1=value1\r\nname2=value2");
}

[Test]
Expand All @@ -80,6 +96,7 @@ public void ToString_should_ignore_empty_headers()
var response = new Response(ResponseCode.Ok, headers: Headers.Empty);

response.ToString(true).Should().Be("200 Ok");
response.ToString(true, true).Should().Be("200 Ok");
}

[Test]
Expand All @@ -88,6 +105,7 @@ public void ToString_should_ignore_null_headers()
var response = new Response(ResponseCode.Ok);

response.ToString(true).Should().Be("200 Ok");
response.ToString(true, true).Should().Be("200 Ok");
}

[TestCase(ResponseCode.InternalServerError)]
Expand Down
Loading

0 comments on commit 991c469

Please sign in to comment.