|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | range_sha=${BASE_SHA} |
4 | | -pr_id=${PR_ID} |
5 | | - |
6 | | -update_source_count=`git diff --name-status ${range_sha}| awk '{print $2}' | egrep "^tencentcloud/resource_tc|^tencentcloud/data_source" | egrep -v "_test.go" | wc -l` |
7 | | -if [ $update_source_count -eq 0 ]; then |
8 | | - printf "No source change, skip delta-test!" |
9 | | - exit 0 |
10 | | -fi |
11 | | - |
12 | | -if [ ! -f ".changelog/${pr_id}.txt" ]; then |
13 | | - printf "Not find changelog file!" |
14 | | - exit 1 |
| 4 | +echo $(git diff --name-status ${range_sha} | awk '{print $2}') |
| 5 | +#service files |
| 6 | +update_service_functions="" |
| 7 | +service_files=`git diff --name-status ${range_sha} | awk '{print $2}' | grep "^tencentcloud/service*"` |
| 8 | +if [ $service_files ] ; then |
| 9 | + update_service_functions=`echo $service_files | xargs git diff ${range_sha} | grep "@@" | grep "func" | awk -F ")" '{print $2}' | awk -F "(" '{print $1}' | tr -d ' '` |
15 | 10 | fi |
16 | | -source_names=`cat .changelog/${pr_id}.txt| grep -E "^(resource|datasource)\/(\w+)" | awk -F ":" '{print $1}' | sort | uniq` |
17 | | - |
18 | | -test_files="" |
19 | | -for source_name in $source_names; do |
20 | | - name=${source_name#*/} |
21 | | - type=${source_name%/*} |
22 | | - if [ $type == "datasource" ]; then |
23 | | - type=dataSource |
24 | | - fi |
25 | | - # echo $source_name $type $name |
26 | | - function_name=$(cat tencentcloud/provider.go | grep "\"${name}\"" | grep "${type}") |
27 | | - function_name=${function_name#*:} |
28 | | - function_name=$(echo $(echo ${function_name%,*})) |
29 | | - |
30 | | - test_file=$(grep -r "func $function_name \*schema\.Resource" tencentcloud) |
31 | | - test_file=${test_file#*/} |
32 | | - test_file=${test_file%:*} |
33 | | - test_files="$test_files $test_file" |
| 11 | +echo "update_service_functions: $update_service_functions" |
| 12 | +need_test_files="" |
| 13 | +for update_service_function in $update_service_functions; do |
| 14 | + tmp_files=`grep -r --with-filename $update_service_function ./tencentcloud | awk -F ":" '{print $1}' | grep -v "service_tencent*" | awk -F "/" '{print $3}' | sort | uniq | egrep "^resource_tc_|^data_source_tc" | awk -F "." '{print $1}' | awk '/_test$/{print "tencentcloud/"$0".go"} !/_test$/{print "tencentcloud/"$0"_test.go"}'` |
| 15 | + need_test_files="$need_test_files $tmp_files" |
34 | 16 | done |
35 | | -echo "test files:" $test_files |
36 | | - |
37 | | -for test_file in $test_files; do |
38 | | - test_case_type=${test_file%_tc*} |
39 | | - test_case_name=${test_file#*tc_} |
40 | | - test_case_name=${test_case_name%.*} |
| 17 | +echo "need_test_files: $need_test_files" |
41 | 18 |
|
42 | | - test_case_type=`echo $test_case_type | sed -r 's/(^|_)(\w)/\U\2/g'` |
43 | | - test_case_name=`echo $test_case_name | sed -r 's/(^|_)(\w)/\U\2/g'` |
44 | | - |
45 | | - go_test_cmd="go test -v -run TestAccTencentCloud${test_case_name}${test_case_type} -timeout=0 ./tencentcloud/" |
46 | | - echo $go_test_cmd |
47 | | - $go_test_cmd |
48 | | - if [ $? -ne 0 ]; then |
49 | | - printf "[GO TEST FILED] ${go_test_cmd}" |
50 | | - exit 1 |
51 | | - fi |
| 19 | +# resource&&data_source files |
| 20 | +update_sources=`git diff --name-status ${range_sha}| awk '{print $2}' | egrep "^tencentcloud/resource_tc|^tencentcloud/data_source" | egrep -v "_test.go" | awk -F "." '{print $1"_test.go"}'` |
| 21 | +echo "update_sources: $update_sources" |
| 22 | +# test files |
| 23 | +delta_test_files=`git diff --name-status ${range_sha} | egrep "_test\.go$" | awk '{print $2}'` |
| 24 | +echo "delta_test_files: $delta_test_files" |
| 25 | +# all test files |
| 26 | +delta_test_files="$delta_test_files $need_test_files $update_sources" |
| 27 | +delta_test_files=`echo $delta_test_files | xargs -n1 | sort | uniq` |
| 28 | +echo "all delta_test_files: $delta_test_files" |
| 29 | +for delta_test_file in ${delta_test_files}; do |
| 30 | + test_casts=`egrep "func TestAcc.+\(" ${delta_test_file} | awk -F "(" '{print $1}' | awk '{print $2}' | grep -v "NeedFix"` |
| 31 | + echo "[$delta_test_file] \n$test_casts" |
| 32 | + for test_cast in ${test_casts}; do |
| 33 | + go_test_cmd="go test -v -run ${test_cast} -timeout=0 ./tencentcloud/" |
| 34 | + $go_test_cmd |
| 35 | + if [ $? -ne 0 ]; then |
| 36 | + printf "[GO TEST FILED] ${go_test_cmd}" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + done |
52 | 40 | done |
0 commit comments