-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80bc343
commit 8eccaee
Showing
15 changed files
with
243 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: "E2E Tests" | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
integration: | ||
name: End to End Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Nix | ||
uses: DeterminateSystems/nix-installer-action@v4 | ||
- name: Run the Magic Nix Cache | ||
uses: DeterminateSystems/magic-nix-cache-action@v2 | ||
- uses: actions/checkout@v3 | ||
- name: Run e2e tests | ||
run: nix develop -c make e2e | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,7 @@ Cargo.lock | |
*.pdb | ||
|
||
.direnv/ | ||
|
||
- | ||
.e2e-logs | ||
.cala |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "helpers" | ||
|
||
setup_file() { | ||
reset_pg | ||
start_server | ||
} | ||
|
||
teardown_file() { | ||
stop_server | ||
} | ||
|
||
|
||
@test "rust: entities sync to server" { | ||
variables=$( | ||
jq -n \ | ||
'{ | ||
input: { | ||
name: "rust-example", | ||
endpoint: "http://localhost:2253" | ||
} | ||
}' | ||
) | ||
|
||
exec_graphql 'import-job-create' "$variables" | ||
|
||
name=$(graphql_output '.data.importJobCreate.importJob.name') | ||
[[ "$name" == "rust-example" ]] || exit 1; | ||
|
||
|
||
cargo run --bin cala-ledger-example-rust | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mutation importJobCreate($input: ImportJobCreateInput!) { | ||
importJobCreate(input: $input) { | ||
importJob { | ||
importJobId | ||
name | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
REPO_ROOT=$(git rev-parse --show-toplevel) | ||
GQL_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/gql" | ||
COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-${REPO_ROOT##*/}}" | ||
|
||
GQL_ENDPOINT="http://localhost:2252/graphql" | ||
|
||
CALA_HOME="${CALA_HOME:-.cala}" | ||
|
||
reset_pg() { | ||
docker exec "${COMPOSE_PROJECT_NAME}-server-pg-1" psql $PG_CON -c "DROP SCHEMA public CASCADE" | ||
docker exec "${COMPOSE_PROJECT_NAME}-server-pg-1" psql $PG_CON -c "CREATE SCHEMA public" | ||
docker exec "${COMPOSE_PROJECT_NAME}-examples-pg-1" psql $PG_CON -c "DROP SCHEMA public CASCADE" | ||
docker exec "${COMPOSE_PROJECT_NAME}-examples-pg-1" psql $PG_CON -c "CREATE SCHEMA public" | ||
} | ||
|
||
server_cmd() { | ||
server_location=${REPO_ROOT}/target/debug/cala-server | ||
if [[ ! -z ${CARGO_TARGET_DIR} ]] ; then | ||
server_location=${CARGO_TARGET_DIR}/debug/cala-server | ||
fi | ||
|
||
${server_location} $@ | ||
} | ||
|
||
start_server() { | ||
background server_cmd > .e2e-logs | ||
for i in {1..20} | ||
do | ||
if head .e2e-logs | grep -q 'Starting graphql server on port'; then | ||
break | ||
else | ||
sleep 1 | ||
fi | ||
done | ||
} | ||
|
||
stop_server() { | ||
if [[ -f ${CALA_HOME}/server-pid ]]; then | ||
kill -9 $(cat ${CALA_HOME}/server-pid) || true | ||
fi | ||
} | ||
|
||
gql_file() { | ||
echo "${GQL_DIR}/$1.gql" | ||
} | ||
|
||
gql_query() { | ||
cat "$(gql_file $1)" | tr '\n' ' ' | sed 's/"/\\"/g' | ||
} | ||
|
||
graphql_output() { | ||
echo $output | jq -r "$@" | ||
} | ||
|
||
exec_graphql() { | ||
local query_name=$1 | ||
local variables=${2:-"{}"} | ||
|
||
if [[ "${BATS_TEST_DIRNAME}" != "" ]]; then | ||
run_cmd="run" | ||
else | ||
run_cmd="" | ||
fi | ||
|
||
${run_cmd} curl -s \ | ||
-X POST \ | ||
${AUTH_HEADER:+ -H "$AUTH_HEADER"} \ | ||
-H "Content-Type: application/json" \ | ||
-d "{\"query\": \"$(gql_query $query_name)\", \"variables\": $variables}" \ | ||
"${GQL_ENDPOINT}" | ||
} | ||
|
||
# Run the given command in the background. Useful for starting a | ||
# node and then moving on with commands that exercise it for the | ||
# test. | ||
# | ||
# Ensures that BATS' handling of file handles is taken into account; | ||
# see | ||
# https://github.com/bats-core/bats-core#printing-to-the-terminal | ||
# https://github.com/sstephenson/bats/issues/80#issuecomment-174101686 | ||
# for details. | ||
background() { | ||
"$@" 3>- & | ||
echo $! | ||
} | ||
|
||
# Taken from https://github.com/docker/swarm/blob/master/test/integration/helpers.bash | ||
# Retry a command $1 times until it succeeds. Wait $2 seconds between retries. | ||
retry() { | ||
local attempts=$1 | ||
shift | ||
local delay=$1 | ||
shift | ||
local i | ||
|
||
for ((i=0; i < attempts; i++)); do | ||
run "$@" | ||
if [[ "$status" -eq 0 ]] ; then | ||
return 0 | ||
fi | ||
sleep "$delay" | ||
done | ||
|
||
echo "Command \"$*\" failed $attempts times. Output: $output" | ||
false | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters