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

Refactor TestHttpCredentialsProvider #159

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

pranavr12
Copy link
Contributor

The refactor allows reusing of classes for custom implementations of the HTTP Credentials Provider

public static class Filter
implements BuilderFilter
{
private static String httpEndpointUri;
Copy link
Member

Choose a reason for hiding this comment

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

This should be a local variable


import jakarta.servlet.Servlet;

public interface TestHttpCredentialsServlet
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be named closer to its purpose. Maybe TestHttpCredentialsCounts or something like that.

Copy link
Member

Choose a reason for hiding this comment

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

This could perhaps also be moved to the testing package

import jakarta.servlet.Servlet;

public interface TestHttpCredentialsServlet
extends Servlet
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't extend Servlet


TestHttpCredentialsServlet httpCredentialsServlet;
try {
httpCredentialsServlet = new TestHttpCredentialsServletImpl(expectedHeaders);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
httpCredentialsServlet = new TestHttpCredentialsServletImpl(expectedHeaders);
TestHttpCredentialsServletImpl testHttpCredentialsServlet = new TestHttpCredentialsServletImpl(expectedHeaders);
httpCredentialsServlet = testHttpCredentialsServlet;
httpCredentialsServer = createTestingHttpCredentialsServer(testHttpCredentialsServlet);

Then you can remove the extends Servlet


import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;

public class TestHttpCredentialsServletImpl
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need a generic interface for this, it's a Testing HTTP server, we could remove the interface and make everything use this class

private static String httpEndpointUri;

@Override
public TestingTrinoAwsProxyServer.Builder filter(TestingTrinoAwsProxyServer.Builder builder)
Copy link
Member

Choose a reason for hiding this comment

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

This filter, unlike the TestingHttpCredentialsServlet, would be of limited use to anything except for a single test class (where it was moved from), I think that it should be moved back under TestHttpCredentialsProvider

@@ -186,74 +180,12 @@ private void testNoCredentialsRetrieved(String emulatedAccessKey, Optional<Strin
assertThat(httpCredentialsServlet.getRequestCount()).isEqualTo(1);
}

private static TestingHttpServer createTestingHttpCredentialsServer(HttpCredentialsServlet servlet)
protected static TestingHttpServer createTestingHttpCredentialsServer(Servlet servlet)
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be public and moved to TestingUtils or some other class since its not specific to the credentials server. we have another function called createTestingHttpErrorResponseServer which does the same thing and could be replaced by this

@pranavr12 pranavr12 force-pushed the refactor-http-creds-tests branch 2 times, most recently from e4433ca to 17edac4 Compare October 2, 2024 16:24
@@ -148,4 +154,13 @@ public static String sha256(String content)
{
return Hashing.sha256().newHasher().putString(content, StandardCharsets.UTF_8).hash().toString();
}

public static TestingHttpServer createTestingHttpServer(Servlet servlet)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we reuse this in TestProxiedErrorResponses please?

Copy link
Contributor

@mosiac1 mosiac1 left a comment

Choose a reason for hiding this comment

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

LGTM

@mosiac1 mosiac1 merged commit e9b02da into trinodb:main Oct 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants