Skip to content

Commit

Permalink
fix test builder when dns resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Maldini committed Oct 25, 2017
1 parent f7a2df4 commit f600a9c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,22 @@ public void asDetailedString() {
//proxy
this.builder.proxy(proxyOptions);
assertThat(this.builder.build().asDetailedString())
.startsWith("connectAddress=null, proxy=SOCKS4(http://proxy:456)")
.startsWith("connectAddress=null, proxy=SOCKS4(http://proxy")
.contains(":456)")
.endsWith(", acceptGzip=false");

//address
this.builder.host("http://google.com").port(123);
assertThat(this.builder.build().asDetailedString())
.startsWith("connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy:456)")
.startsWith("connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy")
.contains(":456)")
.endsWith(", acceptGzip=false");

//gzip
this.builder.compression(true);
assertThat(this.builder.build().asDetailedString())
.startsWith("connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy:456)")
.startsWith("connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy")
.contains(":456)")
.endsWith(", acceptGzip=true");
}

Expand All @@ -85,7 +88,8 @@ public void toStringContainsAsDetailedString() {
.proxy(proxyOptions)
.compression(true);
assertThat(this.builder.build().toString())
.startsWith("HttpClientOptions{connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy:456)")
.startsWith("HttpClientOptions{connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy")
.contains(":456)")
.endsWith(", acceptGzip=true}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ public void asDetailedString() {
public void toStringContainsAsDetailedString() {
HttpServerOptions.Builder builder = HttpServerOptions.builder()
.compression(534)
.host("http://google.com")
.host("google.com")
.port(123);
assertThat(builder.build().toString())
.startsWith("HttpServerOptions{address=http://google.com:123")
.startsWith("HttpServerOptions{address=google.com")
.contains(":123")
.endsWith(", minCompressionResponseSize=534}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ public void asDetailedString() {
//proxy
this.builder.proxy(this.proxyOptions);
assertThat(this.builder.build().asDetailedString())
.startsWith("connectAddress=null, proxy=SOCKS4(http://proxy:456)");
.startsWith("connectAddress=null, proxy=SOCKS4(http://proxy")
.contains(":456)");

//address
this.builder.host("http://google.com").port(123);
assertThat(this.builder.build().asDetailedString())
.startsWith("connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy:456)");
.startsWith("connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy")
.contains(":456)");
}

@Test
Expand All @@ -72,7 +74,8 @@ public void toStringContainsAsDetailedString() {
.proxy(proxyOptions)
.build();
assertThat(this.builder.build().toString())
.startsWith("ClientOptions{connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy:456)")
.startsWith("ClientOptions{connectAddress=http://google.com:123, proxy=SOCKS4(http://proxy")
.contains(":456)")
.endsWith("}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/
package reactor.ipc.netty.options;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.InetSocketAddress;

import org.junit.Test;

import io.netty.handler.proxy.HttpProxyHandler;
import io.netty.handler.proxy.Socks4ProxyHandler;
import io.netty.handler.proxy.Socks5ProxyHandler;
import org.junit.Test;
import reactor.ipc.netty.options.ClientProxyOptions.Proxy;

import static org.assertj.core.api.Assertions.assertThat;

public class ClientProxyOptionsTests {

@Test
Expand All @@ -34,10 +33,12 @@ public void asSimpleString() {

ClientProxyOptions.AddressSpec addrSpec = typeSpec.type(Proxy.HTTP);
ClientProxyOptions.Builder builder = addrSpec.host("http://proxy").port(456);
assertThat(builder.build().asSimpleString()).isEqualTo("proxy=HTTP(http://proxy:456)");
assertThat(builder.build().asSimpleString()).startsWith("proxy=HTTP" +
"(http://proxy").endsWith(":456)");

builder = addrSpec.address(new InetSocketAddress("http://another.proxy", 123));
assertThat(builder.build().asSimpleString()).isEqualTo("proxy=HTTP(http://another.proxy:123)");
assertThat(builder.build().asSimpleString()).startsWith("proxy=HTTP" +
"(http://another.proxy").endsWith(":123)");
}

@Test
Expand All @@ -47,15 +48,18 @@ public void asDetailedString() {
ClientProxyOptions.AddressSpec addrSpec = typeSpec.type(Proxy.HTTP);
ClientProxyOptions.Builder builder = addrSpec.host("http://proxy").port(456);
assertThat(builder.build().asDetailedString())
.isEqualTo("address=http://proxy:456, nonProxyHosts=null, type=HTTP");
.startsWith("address=http://proxy")
.endsWith(":456, nonProxyHosts=null, type=HTTP");

builder = addrSpec.address(() -> new InetSocketAddress("http://another.proxy", 123));
assertThat(builder.build().asDetailedString())
.isEqualTo("address=http://another.proxy:123, nonProxyHosts=null, type=HTTP");
.startsWith("address=http://another.proxy")
.endsWith(":123, nonProxyHosts=null, type=HTTP");

builder.nonProxyHosts("localhost");
assertThat(builder.build().asDetailedString())
.isEqualTo("address=http://another.proxy:123, nonProxyHosts=localhost, type=HTTP");
.startsWith("address=http://another.proxy")
.endsWith(":123, nonProxyHosts=localhost, type=HTTP");
}

@Test
Expand All @@ -64,8 +68,9 @@ public void toStringContainsAsDetailedString() {
ClientProxyOptions.Builder builder = typeSpec.type(Proxy.HTTP)
.host("http://proxy")
.port(456);
assertThat(builder.build().toString()).isEqualTo(
"ClientProxyOptions{address=http://proxy:456, nonProxyHosts=null, type=HTTP}");
assertThat(builder.build().toString()).startsWith(
"ClientProxyOptions{address=http://proxy")
.endsWith(":456, nonProxyHosts=null, type=HTTP}");
}

@Test
Expand All @@ -76,7 +81,7 @@ public void getProxyHandlerTypeHttp() {
.port(456);

assertThat(builder.build().newProxyHandler()).isInstanceOf(HttpProxyHandler.class);
assertThat(builder.build().newProxyHandler().proxyAddress().toString()).isEqualTo("http://proxy:456");
assertThat(builder.build().newProxyHandler().proxyAddress().toString()).startsWith("http://proxy").endsWith(":456");

builder.username("test1");
assertThat(((HttpProxyHandler) builder.build().newProxyHandler()).username()).isNull();
Expand All @@ -94,7 +99,7 @@ public void getProxyHandlerTypeSocks4() {
.port(456);

assertThat(builder.build().newProxyHandler()).isInstanceOf(Socks4ProxyHandler.class);
assertThat(builder.build().newProxyHandler().proxyAddress().toString()).isEqualTo("http://proxy:456");
assertThat(builder.build().newProxyHandler().proxyAddress().toString()).startsWith("http://proxy").endsWith(":456");

builder.username("test1");
assertThat(((Socks4ProxyHandler) builder.build().newProxyHandler()).username()).isEqualTo("test1");
Expand All @@ -108,7 +113,7 @@ public void getProxyHandlerTypeSocks5() {
.port(456);

assertThat(builder.build().newProxyHandler()).isInstanceOf(Socks5ProxyHandler.class);
assertThat(builder.build().newProxyHandler().proxyAddress().toString()).isEqualTo("http://proxy:456");
assertThat(builder.build().newProxyHandler().proxyAddress().toString()).startsWith("http://proxy").endsWith(":456");

builder.username("test1");
assertThat(((Socks5ProxyHandler) builder.build().newProxyHandler()).username()).isNull();
Expand Down

0 comments on commit f600a9c

Please sign in to comment.