-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbt_test.sh
More file actions
executable file
·71 lines (54 loc) · 1.81 KB
/
dbt_test.sh
File metadata and controls
executable file
·71 lines (54 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -ex
#################################################
# in case specific model or test case is provided
specific_model="ALL"
specific_test_case="ALL"
while getopts m:t: flag
do
case "${flag}" in
m) specific_model=${OPTARG};;
t) specific_test_case=${OPTARG};;
esac
done
#################################################
# insert the seed data needed for the tests
seeds="$( cat ./conf_test/tests_definitions.csv| cut -d, -f1| uniq )"
for seed in ${seeds[*]}
do
if [[ "$specific_model" == "ALL" ]] || [[ "$specific_model" == "$seed" ]]; then
# skip lines that start with #
if [[ $seed = \#* ]]; then
continue
fi
dbt seed --full-refresh -m MOCK_$seed --vars '{"test_mode":true}'
fi
done
#################################################
pop_n_test(){
# populate the model and test it
model=$1
test_id=$2
# populate the model with test_id conditions
dbt run -m $model --vars '{"test_mode":true,"test_id":"'"$test_id"'","model_name":"'"$model"'"}'
# test that results are as expected
dbt test --select tag:test_${model}_${test_id} --vars '{"test_mode":true,"test_id":"'"$test_id"'","model_name":"'"$model"'"}'
}
models="$( cat ./conf_test/tests_definitions.csv)"
for pair in ${models}
do
# decompose each rows into human vars
model="$(echo $pair | cut -d, -f1)"
test_id="$(echo $pair | cut -d, -f2)"
if [[ "$specific_model" == "ALL" ]] || [[ "$specific_model" == "$model" ]]; then
if [[ "$specific_test_case" == "ALL" ]] || [[ "$specific_test_case" == "$test_id" ]]; then
#skip lines that start with #
if [[ $pair = \#* ]]; then
continue
fi
# order is important
pop_n_test $model $test_id
fi
fi
done
set +ex