Making the tests less brittle

This commit is contained in:
Marcin Grzejszczak
2021-05-13 14:03:19 +02:00
parent 1e4de4f7fe
commit bfb5e0240b
2 changed files with 6 additions and 3 deletions

View File

@@ -227,8 +227,8 @@ public class WireMockHttpServerStub implements HttpServerStub {
String scheme = this.https ? "https" : "http";
String host = "localhost";
int port = port();
String urlPathPrefix = null;
String hostHeader = null;
String urlPathPrefix = "";
String hostHeader = "";
String proxyHost = this.wireMockConfiguration.proxyHostHeader();
int proxyPort = this.wireMockConfiguration.proxyVia().port();
ClientAuthenticator authenticator = NoClientAuthenticator.noClientAuthenticator();

View File

@@ -19,9 +19,10 @@ package org.springframework.cloud.contract.stubrunner
import spock.lang.Specification
import org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStub
import org.springframework.util.SocketUtils
class StubServerSpec extends Specification {
static final int STUB_SERVER_PORT = 12180
static final int STUB_SERVER_PORT = SocketUtils.findAvailableTcpPort()
static final URL EXPECTED_URL = new URL("http://localhost:$STUB_SERVER_PORT")
File repository = new File('src/test/resources/repository/mappings/spring/cloud/bye')
@@ -36,6 +37,7 @@ class StubServerSpec extends Specification {
pingStubServer.start()
then:
"http://localhost:$pingStubServer.port/bye".toURL().text == 'Goodbye world!'
cleanup:
pingStubServer.stop()
}
@@ -48,6 +50,7 @@ class StubServerSpec extends Specification {
pingStubServer.start()
then:
pingStubServer.stubUrl == EXPECTED_URL
cleanup:
pingStubServer.stop()
}
}