Skip to content
Merged

Fix/e2e #1387

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 47 additions & 0 deletions scripts/changelog-test.sh
Original file line number Diff line number Diff line change
@@ -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
78 changes: 33 additions & 45 deletions scripts/delta-test.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions scripts/dispacher-test.sh
Original file line number Diff line number Diff line change
@@ -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