-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
public static class Filter | ||
implements BuilderFilter | ||
{ | ||
private static String httpEndpointUri; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
6e52c80
to
8796293
Compare
...oxy/src/test/java/io/trino/aws/proxy/server/credentials/http/TestHttpCredentialsServlet.java
Outdated
Show resolved
Hide resolved
...oxy/src/test/java/io/trino/aws/proxy/server/credentials/http/TestHttpCredentialsServlet.java
Outdated
Show resolved
Hide resolved
@@ -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) |
There was a problem hiding this comment.
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
e4433ca
to
17edac4
Compare
trino-aws-proxy/src/test/java/io/trino/aws/proxy/server/testing/TestingUtil.java
Outdated
Show resolved
Hide resolved
17edac4
to
291c6da
Compare
291c6da
to
4ed6436
Compare
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The refactor allows reusing of classes for custom implementations of the HTTP Credentials Provider