Skip to content

Commit

Permalink
Merge pull request #471 from DataRecce/feature/drc-842-extend-smoke-t…
Browse files Browse the repository at this point in the history
…est-coverage

Modify the smoke test
  • Loading branch information
popcornylu authored Oct 31, 2024
2 parents c5cc990 + 8f4a86b commit 5c194ed
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 31 deletions.
9 changes: 9 additions & 0 deletions integration_tests/dbt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
target/
target-base/
dbt_packages/
recce_state.json
recce_summary.md
jaffle_shop.duckdb
.user.yml
package-lock.yml
recce.yml
18 changes: 9 additions & 9 deletions integration_tests/dbt/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ models:
columns:
- name: customer_id
description: This is a unique identifier for a customer
tests:
data_tests:
- unique
- not_null

Expand All @@ -34,14 +34,14 @@ models:

columns:
- name: order_id
tests:
data_tests:
- unique
- not_null
description: This is a unique identifier for an order

- name: customer_id
description: Foreign key to the customers table
tests:
data_tests:
- not_null
- relationships:
to: ref('customers')
Expand All @@ -52,31 +52,31 @@ models:

- name: status
description: '{{ doc("orders_status") }}'
tests:
data_tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']

- name: amount
description: Total amount (AUD) of the order
tests:
data_tests:
- not_null

- name: credit_card_amount
description: Amount of the order (AUD) paid for by credit card
tests:
data_tests:
- not_null

- name: coupon_amount
description: Amount of the order (AUD) paid for by coupon
tests:
data_tests:
- not_null

- name: bank_transfer_amount
description: Amount of the order (AUD) paid for by bank transfer
tests:
data_tests:
- not_null

- name: gift_card_amount
description: Amount of the order (AUD) paid for by gift card
tests:
data_tests:
- not_null
10 changes: 5 additions & 5 deletions integration_tests/dbt/models/staging/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ models:
- name: stg_customers
columns:
- name: customer_id
tests:
data_tests:
- unique
- not_null

- name: stg_orders
columns:
- name: order_id
tests:
data_tests:
- unique
- not_null
- name: status
tests:
data_tests:
- accepted_values:
values: ['placed', 'shipped', 'completed', 'return_pending', 'returned']

- name: stg_payments
columns:
- name: payment_id
tests:
data_tests:
- unique
- not_null
- name: payment_method
tests:
data_tests:
- accepted_values:
values: ['credit_card', 'coupon', 'bank_transfer', 'gift_card']
58 changes: 41 additions & 17 deletions integration_tests/dbt/smoke_test.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,75 @@
#!/usr/bin/env bash
set -euxo pipefail
set -euo pipefail

FALLBACK_PR_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/${GITHUB_REF_NAME}"
PR_URL="${PR_URL:-$FALLBACK_PR_URL}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
pwd

# Step 1: prepare env
# Prepare env
git restore models/customers.sql
dbt --version
dbt deps
dbt build --target-path target-base
dbt seed --target-path target-base
dbt run --target-path target-base
dbt docs generate --target-path target-base

# modify model
echo "where customer_id > 0" >> models/customers.sql
dbt build
dbt run
dbt docs generate
git restore models/customers.sql

# Step 2: turn off anonymous tracking
mkdir ~/.recce
# Recce Run
mkdir -p ~/.recce
echo "user_id: 00000000000000000000000000000000" > ~/.recce/profile.yml
echo "anonymous_tracking: false" >> ~/.recce/profile.yml

# Step 3: add helper function
assert_string_value() {
if [ "$1" != "$2" ]; then
echo "Expected $2, but got $1"
exit 1
fi
}

# Test
recce run

# state file generated
if ! [ -e recce_state.json ]; then
echo "recce_state.json not found"
exit 1
fi

# row count diff to modified table models
model=$(cat recce_state.json | jq '.runs[0].result | keys | .[0]' | tr -d '"')
run_type=$(cat recce_state.json | jq '.runs[0]'.type | tr -d '"')
assert_string_value $model "customers"
assert_string_value $run_type "row_count_diff"

# pull request information
pr_url=$(cat recce_state.json | jq .pull_request.url | tr -d '"')
assert_string_value "${pr_url}" "${PR_URL}"
# Recce Summary
recce summary ./recce_state.json | tee recce_summary.md
cat ./recce_summary.md | grep -q customers

# Recce Server
function check_server_status() {
echo "Waiting for the server to respond..."
if timeout 20 bash -c 'until curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/api/info | grep -q 200; do
echo "Server not ready yet..."
sleep 2
done'; then
echo "Server is up and running."
EXITCODE=0
else
echo "Failed to start the server within the time limit."
EXITCODE=1
fi

echo "Stopping the server..."
kill $(jobs -p) || true
echo "Server stopped."

exit $EXITCODE
}

echo "Starting the server..."
recce server &
check_server_status

echo "Starting the server (review mode)"
recce server --review recce_state.json &
check_server_status

0 comments on commit 5c194ed

Please sign in to comment.