Skip to content

Commit

Permalink
refactor(example tests): merged tests into the original markdowns, etc
Browse files Browse the repository at this point in the history
Merged tests into the original markdowns. Also fixed to add all the directories in the example
directory as test targets.

Signed-off-by: Taiga Nakayama <dora@dora-gt.jp>
  • Loading branch information
dora-gt committed Sep 17, 2019
1 parent 3f4576c commit 9811824
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 69 deletions.
12 changes: 12 additions & 0 deletions examples/eth-settlement/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,15 @@ You might have run another example. Stop them first and try again. How to stop t
This example showed an SPSP payment sent between two Interledger.rs nodes that settled using on-ledger Ethereum transactions.

Check out the [other examples](../README.md) for more complex demos that show other features of Interledger, including multi-hop routing and cross-currency payments.

<!--!
# For integration tests
function hook_before_kill() {
if [ $TEST_MODE -eq 1 ]; then
test_equals_or_exit '{"balance":"-500"}' test_http_response_body -H "Authorization: Bearer alice:in_alice" http://localhost:7770/accounts/alice/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer bob:bob_password" http://localhost:7770/accounts/bob/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer alice:alice_password" http://localhost:8770/accounts/alice/balance
test_equals_or_exit '{"balance":"500"}' test_http_response_body -H "Authorization: Bearer bob:in_bob" http://localhost:8770/accounts/bob/balance
fi
}
-->
14 changes: 14 additions & 0 deletions examples/eth-xrp-three-nodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1037,3 +1037,17 @@ You might have run another example. Stop them first and try again. How to stop t
This example showed an SPSP payment sent between three Interledger.rs nodes that settled using on-ledger Ethereum and XRPL transactions.

More examples that enhance your integration with ILP are coming soon!

<!--!
# For integration tests
function hook_before_kill() {
if [ $TEST_MODE -eq 1 ]; then
test_equals_or_exit '{"balance":"-500"}' test_http_response_body -H "Authorization: Bearer hi_alice" http://localhost:7770/accounts/alice/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer hi_alice" http://localhost:7770/accounts/bob/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer hi_bob" http://localhost:8770/accounts/alice/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer hi_bob" http://localhost:8770/accounts/charlie/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer hi_charlie" http://localhost:9770/accounts/bob/balance
test_equals_or_exit '{"balance":"500"}' test_http_response_body -H "Authorization: Bearer hi_charlie" http://localhost:9770/accounts/charlie/balance
fi
}
-->
12 changes: 12 additions & 0 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,15 @@ You might have run another example. Stop them first and try again. How to stop t
That's it for this example! You've learned how to set up Interledger.rs nodes, connect them together, and how to send a payment from one to the other.

Check out the [other examples](../README.md) for more complex demos that show other features of Interledger, including settlement, multi-hop routing, and cross-currency payments.

<!--!
# For integration tests
function hook_before_kill() {
if [ $TEST_MODE -eq 1 ]; then
test_equals_or_exit '{"balance":"-500"}' test_http_response_body -H "Authorization: Bearer admin-a" http://localhost:7770/accounts/alice/balance
test_equals_or_exit '{"balance":"500"}' test_http_response_body -H "Authorization: Bearer admin-a" http://localhost:7770/accounts/node_b/balance
test_equals_or_exit '{"balance":"-500"}' test_http_response_body -H "Authorization: Bearer admin-b" http://localhost:8770/accounts/node_a/balance
test_equals_or_exit '{"balance":"500"}' test_http_response_body -H "Authorization: Bearer admin-b" http://localhost:8770/accounts/bob/balance
fi
}
-->
12 changes: 12 additions & 0 deletions examples/xrp-settlement/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,15 @@ You might have run another example. Stop them first and try again. How to stop t
This example showed an SPSP payment sent between two Interledger.rs nodes that settled using on-ledger XRP transactions.

Check out the [other examples](../README.md) for more complex demos that show other features of Interledger, including multi-hop routing and cross-currency payments.

<!--!
# For integration tests
function hook_before_kill() {
if [ $TEST_MODE -eq 1 ]; then
test_equals_or_exit '{"balance":"-500"}' test_http_response_body -H "Authorization: Bearer alice:in_alice" http://localhost:7770/accounts/alice/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer bob:bob_password" http://localhost:7770/accounts/bob/balance
test_equals_or_exit '{"balance":"0"}' test_http_response_body -H "Authorization: Bearer alice:alice_password" http://localhost:8770/accounts/alice/balance
test_equals_or_exit '{"balance":"500"}' test_http_response_body -H "Authorization: Bearer bob:in_bob" http://localhost:8770/accounts/bob/balance
fi
}
-->
63 changes: 29 additions & 34 deletions scripts/run-md-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,47 @@ function clear_redis_file() {
fi
}

# $1 = example name
# $1 = target directory
# $2 = docker mode in [01]
#
# test_example eth-settlement
#
# This heavily depends on the naming convention.
# - "run-md-tests/examples/$1.sh" MUST exist
# - "$BASE_DIR/../examples/$1" MUST exist
# test_example examples/eth-settlement 0
function test_example() {
local target_name=$1
local target_directory=$1
local docker_mode=$2
local target_name=$(basename $target_directory)

# doing in a sub-shell because we want to load `hook_before_kill` many times
(
cd $BASE_DIR/../examples/$target_name
source ../../scripts/run-md-tests/examples/${target_name}.sh
export -f hook_before_kill
if [ $docker_mode -eq 1 ]; then
printf "\e[33;1m%b [%d/%d]\e[m\n" "Testing \"${target_name}\" on docker mode." "$((TESTING_INDEX + 1))" "${TESTS_TOTAL}"
init_test; TEST_MODE=1 USE_DOCKER=1 $RUN_MD .
return $?
else
printf "\e[33;1m%b [%d/%d]\e[m\n" "Testing \"${target_name}\" on non-docker mode." "$((TESTING_INDEX + 1))" "${TESTS_TOTAL}"
init_test; TEST_MODE=1 $RUN_MD .
return $?
fi
)
cd $target_directory
if [ $docker_mode -eq 1 ]; then
printf "\e[33;1m%b [%d/%d]\e[m\n" "Testing \"${target_name}\" on docker mode." "$((TESTING_INDEX + 1))" "${TESTS_TOTAL}"
init_test; USE_DOCKER=1 $RUN_MD .
return $?
else
printf "\e[33;1m%b [%d/%d]\e[m\n" "Testing \"${target_name}\" on non-docker mode." "$((TESTING_INDEX + 1))" "${TESTS_TOTAL}"
init_test; $RUN_MD .
return $?
fi
}

# Adds all directories in `examples` directory as test targets.
function add_example_tests() {
# This will add tests like "test_example eth-settlement 0" which means an example test of
# eth-settlement in non-docker mode.
for directory in $(find $BASE_DIR/../examples/* -type d -maxdepth 0); do
TESTS+=("test_example ${directory} 0") # this cannot contain space in the directory path
TESTS+=("test_example ${directory} 1")
done
}

BASE_DIR=$(cd $(dirname $0); pwd)
RUN_MD=$BASE_DIR/run-md.sh

tests=()
tests+=("test_example eth-settlement 0")
tests+=("test_example eth-settlement 1")
tests+=("test_example eth-xrp-three-nodes 0")
tests+=("test_example eth-xrp-three-nodes 1")
tests+=("test_example simple 0")
tests+=("test_example simple 1")
tests+=("test_example xrp-settlement 0")
tests+=("test_example xrp-settlement 1")
TESTS_TOTAL=${#tests[@]}
TESTS=()
add_example_tests
TESTS_TOTAL=${#TESTS[@]}
TESTS_FAILED=0
TESTING_INDEX=0
for test in "${tests[@]}"; do
$test
for test in "${TESTS[@]}"; do
TEST_MODE=1 $test
if [ $? -ne 0 ]; then
TESTS_FAILED=$((TESTS_FAILED + 1))
fi
Expand Down
9 changes: 0 additions & 9 deletions scripts/run-md-tests/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/run-md-tests/examples/eth-settlement.sh

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/run-md-tests/examples/eth-xrp-three-nodes.sh

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/run-md-tests/examples/simple.sh

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/run-md-tests/examples/xrp-settlement.sh

This file was deleted.

0 comments on commit 9811824

Please sign in to comment.