Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PATCH in HttpConnection.ConvertHttpMethod #489

Merged

Conversation

assaftir
Copy link
Contributor

Description

Add support for PATCH in HttpConnection.ConvertHttpMethod.

Issues Resolved

Fixes #488

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@assaftir assaftir force-pushed the patch-support-http-connection branch 2 times, most recently from 436476b to e6b6371 Compare December 26, 2023 10:55
@dblock
Copy link
Member

dblock commented Dec 26, 2023

Thanks. Add a test please?

@assaftir
Copy link
Contributor Author

Thanks. Add a test please?

Sure, will do asap.
Any guidance for expected test?

@dblock
Copy link
Member

dblock commented Dec 29, 2023

@assaftir No particular guidance, see if there are any existing tests with verbs. If not add something. I'm happy if the code path is exercised and tests would fail without this change.

Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @assaftir,

Thanks for catching this, don't know how I missed it in the initial feature PR!

I've just got one minor nit about using a const.

As far as testing this, I think the simplest possible would be something like the following added to the Tests project:

/* SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 */

using System;
using FluentAssertions;
using OpenSearch.Net;
using OpenSearch.OpenSearch.Xunit.XunitPlumbing;
using Xunit;

namespace Tests.Connection.Http;

public class HttpConnectionTests
{
	public static TheoryData<HttpMethod> HttpMethods()
	{
		var data = new TheoryData<HttpMethod>();
		foreach (var httpMethod in Enum.GetValues<HttpMethod>()) data.Add(httpMethod);
		return data;
	}

	[TU]
	[MemberData(nameof(HttpMethods))]
	public void ConvertHttpMethod_ConvertsMethod(HttpMethod method)
	{
		var converted = HttpConnection.ConvertHttpMethod(method);
		converted.ToString().Should().BeEquivalentTo(method.ToString());
	}
}

But it's debatable whether this is a good test as it's directly prodding an implementation detail of HttpConnection. Otherwise could do something like https://github.com/opensearch-project/opensearch-net/blob/main/tests/Tests.Auth.AwsSigV4/AwsSigV4HttpConnectionTests.cs and create a mockable subclass of HttpConnection, then using same theory data and calling low-level HTTP method then asserting on the constructed HttpRequestMessage

src/OpenSearch.Net/Connection/HttpConnection.cs Outdated Show resolved Hide resolved
@Xtansia
Copy link
Collaborator

Xtansia commented Jan 8, 2024

This will also need an entry added to the Unreleased section of the CHANGELOG.md under a Fixed heading

@assaftir assaftir force-pushed the patch-support-http-connection branch from e6b6371 to e2ad643 Compare January 8, 2024 16:16
@assaftir
Copy link
Contributor Author

assaftir commented Jan 8, 2024

Hi @assaftir,

Thanks for catching this, don't know how I missed it in the initial feature PR!

I've just got one minor nit about using a const.

As far as testing this, I think the simplest possible would be something like the following added to the Tests project:

/* SPDX-License-Identifier: Apache-2.0

 *

 * The OpenSearch Contributors require contributions made to

 * this file be licensed under the Apache-2.0 license or a

 * compatible open source license.

 */



using System;

using FluentAssertions;

using OpenSearch.Net;

using OpenSearch.OpenSearch.Xunit.XunitPlumbing;

using Xunit;



namespace Tests.Connection.Http;



public class HttpConnectionTests

{

	public static TheoryData<HttpMethod> HttpMethods()

	{

		var data = new TheoryData<HttpMethod>();

		foreach (var httpMethod in Enum.GetValues<HttpMethod>()) data.Add(httpMethod);

		return data;

	}



	[TU]

	[MemberData(nameof(HttpMethods))]

	public void ConvertHttpMethod_ConvertsMethod(HttpMethod method)

	{

		var converted = HttpConnection.ConvertHttpMethod(method);

		converted.ToString().Should().BeEquivalentTo(method.ToString());

	}

}

But it's debatable whether this is a good test as it's directly prodding an implementation detail of HttpConnection. Otherwise could do something like https://github.com/opensearch-project/opensearch-net/blob/main/tests/Tests.Auth.AwsSigV4/AwsSigV4HttpConnectionTests.cs and create a mockable subclass of HttpConnection, then using same theory data and calling low-level HTTP method then asserting on the constructed HttpRequestMessage

I've implemented a test, let me know if it works, otherwise I'll go the route you took with the 'AwsSigV4' tests.

I'm not a huge fan of unit tests and not familiar with the xUnit framework, so forgive me if I haven't done that right.

@assaftir assaftir force-pushed the patch-support-http-connection branch from e2ad643 to 1650a04 Compare January 9, 2024 10:51
@assaftir assaftir requested a review from Xtansia January 9, 2024 10:54
Xtansia
Xtansia previously approved these changes Jan 9, 2024
Signed-off-by: Thomas Farr <[email protected]>
@Xtansia Xtansia merged commit 4e721ee into opensearch-project:main Jan 9, 2024
2 checks passed
@Xtansia Xtansia added the backport 1.x Backport to 1.x branch label Jan 9, 2024
@opensearch-trigger-bot
Copy link
Contributor

The backport to 1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.x 1.x
# Navigate to the new working tree
cd .worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-489-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4e721ee854f90fb66f05002c991492c081b68bf0
# Push it to GitHub
git push --set-upstream origin backport/backport-489-to-1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.x

Then, create a pull request where the base branch is 1.x and the compare/head branch is backport/backport-489-to-1.x.

Xtansia pushed a commit to Xtansia/opensearch-net that referenced this pull request Jan 9, 2024
…arch-project#489)

* Add support for PATCH in HttpConnection.ConvertHttpMethod

Signed-off-by: Assaf Tirangel <[email protected]>

* Fix test

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Assaf Tirangel <[email protected]>
Signed-off-by: Thomas Farr <[email protected]>
Co-authored-by: Assaf Tirangel <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
(cherry picked from commit 4e721ee)
dblock pushed a commit that referenced this pull request Jan 11, 2024
…507)

* Add support for PATCH in HttpConnection.ConvertHttpMethod

Signed-off-by: Assaf Tirangel <[email protected]>

* Fix test

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Assaf Tirangel <[email protected]>
Signed-off-by: Thomas Farr <[email protected]>
Co-authored-by: Assaf Tirangel <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
(cherry picked from commit 4e721ee)

Co-authored-by: assaftir <[email protected]>
@assaftir assaftir deleted the patch-support-http-connection branch January 14, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x Backport to 1.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Missing Case for HttpMethod.PATCH in OpenSearch.Net.HttpConnection.ConvertHttpMethod
3 participants