Skip to content

Instantly share code, notes, and snippets.

@rafaroca
rafaroca / pre-commit
Last active April 18, 2024 14:34
git pre-commit hook to run the gradle ktlint plugin and add changed files to the git index.
#!/bin/sh
set -e
######## KTLINT-GRADLE HOOK START ########
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 ~ /^R/ {print $3}; $1 != "D" && $2 ~ /\.kts|\.kt/ {print $2}')"
if [ -z "$CHANGED_FILES" ]; then
echo "No Kotlin staged files."
exit 0
fi;
@rafaroca
rafaroca / async-consumer-test.kt
Created July 19, 2019 07:42
Consumer-driven asynchronous contract tests
@Pact(consumer = "fulfillment-service", provider = "order-service")
fun exportAnOrderTo(builder: MessagePactBuilder): MessagePact = builder.hasPactWith("order-service")
.given("An order with three items")
.expectsToReceive("an order to export")
.withContent(
newJsonBody { o ->
o.stringType("customerId", testCustomerId)
o.array("items") { a ->
a.newObject { item ->
item.stringType("name", "A Teddy Bear")