diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index d93147ff49..1787688156 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -51,7 +51,7 @@ jobs: # Runs a set of commands using the runners shell - name: e2e tests run: | - make deltatest + make dispachertest if [ $? -ne 0 ]; then printf "COMMIT FAILED\n" exit 1 diff --git a/GNUmakefile b/GNUmakefile index 45bbe4f11f..53262e3cdc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -32,6 +32,12 @@ fmtcheck: deltatest: @sh -c "'$(CURDIR)/scripts/delta-test.sh'" +changelogtest: + @sh -c "'$(CURDIR)/scripts/changelog-test.sh'" + +dispachertest: + @sh -c "'$(CURDIR)/scripts/dispacher-test.sh'" + lint: @echo "==> Checking source code against linters..." @GOGC=30 GOPACKAGESPRINTGOLISTERRORS=1 golangci-lint run --timeout=30m ./$(PKG_NAME) diff --git a/scripts/changelog-test.sh b/scripts/changelog-test.sh new file mode 100755 index 0000000000..c5774718b9 --- /dev/null +++ b/scripts/changelog-test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +pr_id=${PR_ID} + +new_resources=`cat .changelog/${pr_id}.txt| grep -Poz "(?<=release-note:new-resource\n)\w+\n" | awk '{print "resource/"$1}'` +echo new_resources: $new_resources +new_data_sources=`cat .changelog/${pr_id}.txt| grep -Poz "(?<=release-note:new-data-source\n)\w+\n" | awk '{print "datasource/"$1}'` +echo new_data_sources: $new_data_sources +source_names=`cat .changelog/${pr_id}.txt| grep -E "^(resource|datasource)\/(\w+)" | awk -F ":" '{print $1}'` +echo source_names: $source_names +source_names="$source_names $new_resources $new_data_sources" +source_names=`echo $source_names | xargs -n1 | sort | uniq` +test_files="" +for source_name in $source_names; do + name=${source_name#*/} + type=${source_name%/*} + if [ $type == "datasource" ]; then + type=dataSource + fi + # echo $source_name $type $name + function_name=$(cat tencentcloud/provider.go | grep "\"${name}\"" | grep "${type}") + function_name=${function_name#*:} + function_name=$(echo $(echo ${function_name%,*})) + + test_file=$(grep -r "func $function_name \*schema\.Resource" tencentcloud) + test_file=${test_file#*/} + test_file=${test_file%:*} + test_files="$test_files $test_file" +done +echo "test files:" $test_files + +for test_file in $test_files; do + test_case_type=${test_file%_tc*} + test_case_name=${test_file#*tc_} + test_case_name=${test_case_name%.*} + + test_case_type=`echo $test_case_type | sed -r 's/(^|_)(\w)/\U\2/g'` + test_case_name=`echo $test_case_name | sed -r 's/(^|_)(\w)/\U\2/g'` + + go_test_cmd="go test -v -run TestAccTencentCloud${test_case_name}${test_case_type} -timeout=0 ./tencentcloud/" + echo $go_test_cmd + $go_test_cmd + if [ $? -ne 0 ]; then + printf "[GO TEST FILED] ${go_test_cmd}" + exit 1 + fi +done diff --git a/scripts/delta-test.sh b/scripts/delta-test.sh index 5af2cf3fcc..07daa687f6 100755 --- a/scripts/delta-test.sh +++ b/scripts/delta-test.sh @@ -1,52 +1,40 @@ #!/bin/bash range_sha=${BASE_SHA} -pr_id=${PR_ID} - -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` -if [ $update_source_count -eq 0 ]; then - printf "No source change, skip delta-test!" - exit 0 -fi - -if [ ! -f ".changelog/${pr_id}.txt" ]; then - printf "Not find changelog file!" - exit 1 +echo $(git diff --name-status ${range_sha} | awk '{print $2}') +#service files +update_service_functions="" +service_files=`git diff --name-status ${range_sha} | awk '{print $2}' | grep "^tencentcloud/service*"` +if [ $service_files ] ; then + update_service_functions=`echo $service_files | xargs git diff ${range_sha} | grep "@@" | grep "func" | awk -F ")" '{print $2}' | awk -F "(" '{print $1}' | tr -d ' '` fi -source_names=`cat .changelog/${pr_id}.txt| grep -E "^(resource|datasource)\/(\w+)" | awk -F ":" '{print $1}' | sort | uniq` - -test_files="" -for source_name in $source_names; do - name=${source_name#*/} - type=${source_name%/*} - if [ $type == "datasource" ]; then - type=dataSource - fi - # echo $source_name $type $name - function_name=$(cat tencentcloud/provider.go | grep "\"${name}\"" | grep "${type}") - function_name=${function_name#*:} - function_name=$(echo $(echo ${function_name%,*})) - - test_file=$(grep -r "func $function_name \*schema\.Resource" tencentcloud) - test_file=${test_file#*/} - test_file=${test_file%:*} - test_files="$test_files $test_file" +echo "update_service_functions: $update_service_functions" +need_test_files="" +for update_service_function in $update_service_functions; do + 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"}'` + need_test_files="$need_test_files $tmp_files" done -echo "test files:" $test_files - -for test_file in $test_files; do - test_case_type=${test_file%_tc*} - test_case_name=${test_file#*tc_} - test_case_name=${test_case_name%.*} +echo "need_test_files: $need_test_files" - test_case_type=`echo $test_case_type | sed -r 's/(^|_)(\w)/\U\2/g'` - test_case_name=`echo $test_case_name | sed -r 's/(^|_)(\w)/\U\2/g'` - - go_test_cmd="go test -v -run TestAccTencentCloud${test_case_name}${test_case_type} -timeout=0 ./tencentcloud/" - echo $go_test_cmd - $go_test_cmd - if [ $? -ne 0 ]; then - printf "[GO TEST FILED] ${go_test_cmd}" - exit 1 - fi +# resource&&data_source files +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"}'` +echo "update_sources: $update_sources" +# test files +delta_test_files=`git diff --name-status ${range_sha} | egrep "_test\.go$" | awk '{print $2}'` +echo "delta_test_files: $delta_test_files" +# all test files +delta_test_files="$delta_test_files $need_test_files $update_sources" +delta_test_files=`echo $delta_test_files | xargs -n1 | sort | uniq` +echo "all delta_test_files: $delta_test_files" +for delta_test_file in ${delta_test_files}; do + test_casts=`egrep "func TestAcc.+\(" ${delta_test_file} | awk -F "(" '{print $1}' | awk '{print $2}' | grep -v "NeedFix"` + echo "[$delta_test_file] \n$test_casts" + for test_cast in ${test_casts}; do + go_test_cmd="go test -v -run ${test_cast} -timeout=0 ./tencentcloud/" + $go_test_cmd + if [ $? -ne 0 ]; then + printf "[GO TEST FILED] ${go_test_cmd}" + exit 1 + fi + done done diff --git a/scripts/dispacher-test.sh b/scripts/dispacher-test.sh new file mode 100755 index 0000000000..22bb276563 --- /dev/null +++ b/scripts/dispacher-test.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +pr_id=${PR_ID} + +if [ -f ".changelog/${pr_id}.txt" ]; then + make changelogtest + + if [ $? -ne 0 ]; then + printf "COMMIT FAILED\n"s + exit 1 + fi + exit 0 +fi + +make deltatest +if [ $? -ne 0 ]; then + printf "COMMIT FAILED\n" + exit 1 +fi \ No newline at end of file