Skip to content

Commit

Permalink
fix(regression): IO Exceptions are now wrapped #1337
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Apr 11, 2021
1 parent 768e768 commit 30083b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,17 @@ open class PactRunner<I>(private val clazz: Class<*>) : ParentRunner<Interaction
filterPacts(pactLoader.load(serviceName)
.filter { p -> consumerName == null || p.consumer.name == consumerName } as List<Pact<I>>)
} catch (e: IOException) {
if (ignoreIoErrors == "true") {
logger.warn { "\n" + WARNING_ON_IGNORED_IOERROR.trimIndent() }
logger.debug(e) { "Failed to load pact files" }
emptyList<Pact<I>>()
} else {
throw InitializationError(e)
}
checkIgnoreIoException(ignoreIoErrors, e)
} catch (e: JsonException) {
if (ignoreIoErrors == "true") {
logger.warn { "\n" + WARNING_ON_IGNORED_IOERROR.trimIndent() }
logger.debug(e) { "Failed to load pact files" }
emptyList<Pact<I>>()
} else {
throw InitializationError(e)
}
checkIgnoreIoException(ignoreIoErrors, e)
} catch (e: NoPactsFoundException) {
logger.debug(e) { "No pacts found" }
emptyList<Pact<I>>()
} catch (e: Exception) {
when (e.cause) {
is IOException -> checkIgnoreIoException(ignoreIoErrors, e)
else -> throw e
}
}

if (pacts.isEmpty()) {
Expand All @@ -129,6 +122,14 @@ open class PactRunner<I>(private val clazz: Class<*>) : ParentRunner<Interaction
initialized = true
}

private fun checkIgnoreIoException(ignoreIoErrors: String, e: Exception) = if (ignoreIoErrors == "true") {
logger.warn { "\n" + WARNING_ON_IGNORED_IOERROR.trimIndent() }
logger.debug(e) { "Failed to load pact files" }
emptyList<Pact<I>>()
} else {
throw InitializationError(e)
}

protected open fun setupInteractionRunners(testClass: TestClass, pacts: List<Pact<I>>, pactLoader: PactLoader) {
for (pact in pacts) {
this.children.add(newInteractionRunner(testClass, pact, pact.source))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package au.com.dius.pact.provider.junit;

import au.com.dius.pact.provider.junit.target.HttpTarget;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
import au.com.dius.pact.provider.junitsupport.target.Target;
import au.com.dius.pact.provider.junitsupport.target.TestTarget;
import org.junit.runner.RunWith;

@RunWith(PactRunner.class)
@Provider("myAwesomeService")
@IgnoreNoPactsToVerify(ignoreIoErrors = "true")
@PactBroker(host="pact-broker.net.doesnotexist")
public class IgnoreIOErrorsTest {
@TestTarget
public final Target target = new HttpTarget(8332);
}

0 comments on commit 30083b0

Please sign in to comment.