Skip to content

Commit 720b981

Browse files
authored
fix: use kestra_unit_test bq dataset (#68)
1 parent 20da5dc commit 720b981

4 files changed

Lines changed: 61 additions & 5 deletions

File tree

.github/cleanup-unit.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
set -euo pipefail
2+
3+
echo $GOOGLE_SERVICE_ACCOUNT | base64 -d > src/test/resources/.gcp-service-account.json
4+
5+
# Authenticate gcloud with the decoded service account
6+
gcloud auth activate-service-account --key-file=src/test/resources/.gcp-service-account.json
7+
8+
PROJECT_ID="kestra-unit-test"
9+
DATASET="kestra_unit_test"
10+
11+
gcloud config set project "${PROJECT_ID}" >/dev/null
12+
13+
echo "🧹 Deleting test tables from ${PROJECT_ID}:${DATASET}..."
14+
15+
# List of tables created in setup-unit.sh
16+
TABLES=(
17+
"orderDetail"
18+
"territory"
19+
)
20+
21+
for TABLE in "${TABLES[@]}"; do
22+
echo "🗑️ Deleting table ${TABLE}..."
23+
bq rm -f -t "${PROJECT_ID}:${DATASET}.${TABLE}" || echo "⚠️ Table ${TABLE} not found, skipping."
24+
done
25+
26+
echo "✅ Test tables cleaned up successfully"

.github/setup-unit.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
echo $GOOGLE_SERVICE_ACCOUNT | base64 -d > src/test/resources/.gcp-service-account.json
1+
set -euo pipefail
2+
3+
echo $GOOGLE_SERVICE_ACCOUNT | base64 -d > src/test/resources/.gcp-service-account.json
4+
5+
# Authenticate gcloud with the decoded service account
6+
gcloud auth activate-service-account --key-file=src/test/resources/.gcp-service-account.json
7+
8+
PROJECT_ID="kestra-unit-test"
9+
DATASET="kestra_unit_test" # already created via terraform
10+
11+
gcloud config set project "${PROJECT_ID}" >/dev/null
12+
13+
echo "📋 Creating test tables in existing dataset ${PROJECT_ID}:${DATASET}..."
14+
15+
# orderDetail table: used in 'run' and 'error' tests
16+
bq query --use_legacy_sql=false "
17+
CREATE OR REPLACE TABLE \`${PROJECT_ID}.${DATASET}.orderDetail\` AS
18+
SELECT 1 AS id, 10.5 AS unitPrice, TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 DAY) AS addedDate
19+
UNION ALL
20+
SELECT 2 AS id, 200.0 AS unitPrice, TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 2 DAY) AS addedDate;
21+
"
22+
23+
# territory table: used in 'failed' test
24+
bq query --use_legacy_sql=false "
25+
CREATE OR REPLACE TABLE \`${PROJECT_ID}.${DATASET}.territory\` AS
26+
SELECT 1 AS id, 'North' AS name, 1 AS regionId
27+
UNION ALL
28+
SELECT 2 AS id, 'South' AS name, 4 AS regionId;
29+
"
30+
31+
echo "✅ Dataset ${PROJECT_ID}:${DATASET} ready for tests"

src/main/java/io/kestra/plugin/soda/Scan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
type: bigquery
5151
connection:
5252
project_id: kestra-unit-test
53-
dataset: demo
53+
dataset: kestra_unit_test
5454
account_info_json: |
5555
{{ secret('GCP_CREDS') }}
5656
checks:

src/test/java/io/kestra/plugin/soda/ScanTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void run() throws Exception {
3939
" type: bigquery\n" +
4040
" connection:\n" +
4141
" project_id: \"kestra-unit-test\"\n" +
42-
" dataset: demo\n" +
42+
" dataset: kestra_unit_test\n" +
4343
" account_info_json: |\n" +
4444
" " + StringUtils.replace(UtilsTest.serviceAccount(), "\n", "\n "),
4545
TYPE_REFERENCE
@@ -75,7 +75,7 @@ void failed() throws Exception {
7575
" type: bigquery\n" +
7676
" connection:\n" +
7777
" project_id: \"kestra-unit-test\"\n" +
78-
" dataset: demo\n" +
78+
" dataset: kestra_unit_test\n" +
7979
" account_info_json: |\n" +
8080
" " + StringUtils.replace(UtilsTest.serviceAccount(), "\n", "\n "),
8181
TYPE_REFERENCE
@@ -109,7 +109,7 @@ void error() throws Exception {
109109
" type: bigquery\n" +
110110
" connection:\n" +
111111
" project_id: \"kestra-unit-test\"\n" +
112-
" dataset: demo\n" +
112+
" dataset: kestra_unit_test\n" +
113113
" account_info_json: |\n" +
114114
" " + StringUtils.replace(UtilsTest.serviceAccount(), "\n", "\n "),
115115
TYPE_REFERENCE

0 commit comments

Comments
 (0)