Skip to content

Commit

Permalink
refactor: cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoMlt committed Nov 21, 2024
1 parent 93008dd commit ed36dff
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 213 deletions.
20 changes: 9 additions & 11 deletions carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.carapaceproxy;

import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -35,11 +37,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.IOUtils;
import org.carapaceproxy.core.EndpointKey;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.TestEndpointMapper;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -172,7 +171,6 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception {
mockServer.start();

TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort());
EndpointKey key = new EndpointKey("localhost", mockServer.getPort());

int size = 20_000_000;

Expand Down Expand Up @@ -203,16 +201,16 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception {

@Test
public void testBlockingServerWorks() throws Exception {

try (SimpleBlockingTcpServer mockServer =
new SimpleBlockingTcpServer(() -> {
return new StaticResponseHandler("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nit works!\r\n".getBytes(StandardCharsets.US_ASCII));
})) {

SimpleBlockingTcpServer mockServer = new SimpleBlockingTcpServer(() -> new StaticResponseHandler("""
HTTP/1.1 200 OK\r
Content-Type: text/plain\r
\r
it works!\r
""".getBytes(StandardCharsets.US_ASCII)));
try (mockServer) {
mockServer.start();

TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort());
EndpointKey key = new EndpointKey("localhost", mockServer.getPort());

try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
server.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.URI;
import java.nio.charset.StandardCharsets;
Expand All @@ -32,12 +35,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.io.IOUtils;
import org.carapaceproxy.core.EndpointKey;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.TestEndpointMapper;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand All @@ -64,11 +63,10 @@ public void test() throws Exception {
.withBody("it <b>works</b> !!")));

TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
EndpointKey key = new EndpointKey("localhost", wireMockRule.port());

int size = 100;
int concurrentClients = 4;
try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
server.start();
int port = server.getLocalPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
under the License.
*/

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.carapaceproxy.core.HttpProxyServer;
import java.util.Properties;
import org.carapaceproxy.configstore.HerdDBConfigurationStore;
import org.carapaceproxy.configstore.PropertiesConfigurationStore;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.server.filters.RegexpMapUserIdFilter;
import org.carapaceproxy.server.filters.XForwardedForRequestFilter;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
Expand Down
Loading

0 comments on commit ed36dff

Please sign in to comment.