Skip to content

Commit 090824e

Browse files
tongyimingmikatong
andauthored
Fix/e2e (#1387)
* fix e2e * support delta and changelog test * chmod +x for e2e test files * update Co-authored-by: mikatong <mikatong@tencent.com>
1 parent dba8e2f commit 090824e

File tree

5 files changed

+106
-46
lines changed

5 files changed

+106
-46
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
# Runs a set of commands using the runners shell
5252
- name: e2e tests
5353
run: |
54-
make deltatest
54+
make dispachertest
5555
if [ $? -ne 0 ]; then
5656
printf "COMMIT FAILED\n"
5757
exit 1

GNUmakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ fmtcheck:
3232
deltatest:
3333
@sh -c "'$(CURDIR)/scripts/delta-test.sh'"
3434

35+
changelogtest:
36+
@sh -c "'$(CURDIR)/scripts/changelog-test.sh'"
37+
38+
dispachertest:
39+
@sh -c "'$(CURDIR)/scripts/dispacher-test.sh'"
40+
3541
lint:
3642
@echo "==> Checking source code against linters..."
3743
@GOGC=30 GOPACKAGESPRINTGOLISTERRORS=1 golangci-lint run --timeout=30m ./$(PKG_NAME)

scripts/changelog-test.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
pr_id=${PR_ID}
4+
5+
new_resources=`cat .changelog/${pr_id}.txt| grep -Poz "(?<=release-note:new-resource\n)\w+\n" | awk '{print "resource/"$1}'`
6+
echo new_resources: $new_resources
7+
new_data_sources=`cat .changelog/${pr_id}.txt| grep -Poz "(?<=release-note:new-data-source\n)\w+\n" | awk '{print "datasource/"$1}'`
8+
echo new_data_sources: $new_data_sources
9+
source_names=`cat .changelog/${pr_id}.txt| grep -E "^(resource|datasource)\/(\w+)" | awk -F ":" '{print $1}'`
10+
echo source_names: $source_names
11+
source_names="$source_names $new_resources $new_data_sources"
12+
source_names=`echo $source_names | xargs -n1 | sort | uniq`
13+
test_files=""
14+
for source_name in $source_names; do
15+
name=${source_name#*/}
16+
type=${source_name%/*}
17+
if [ $type == "datasource" ]; then
18+
type=dataSource
19+
fi
20+
# echo $source_name $type $name
21+
function_name=$(cat tencentcloud/provider.go | grep "\"${name}\"" | grep "${type}")
22+
function_name=${function_name#*:}
23+
function_name=$(echo $(echo ${function_name%,*}))
24+
25+
test_file=$(grep -r "func $function_name \*schema\.Resource" tencentcloud)
26+
test_file=${test_file#*/}
27+
test_file=${test_file%:*}
28+
test_files="$test_files $test_file"
29+
done
30+
echo "test files:" $test_files
31+
32+
for test_file in $test_files; do
33+
test_case_type=${test_file%_tc*}
34+
test_case_name=${test_file#*tc_}
35+
test_case_name=${test_case_name%.*}
36+
37+
test_case_type=`echo $test_case_type | sed -r 's/(^|_)(\w)/\U\2/g'`
38+
test_case_name=`echo $test_case_name | sed -r 's/(^|_)(\w)/\U\2/g'`
39+
40+
go_test_cmd="go test -v -run TestAccTencentCloud${test_case_name}${test_case_type} -timeout=0 ./tencentcloud/"
41+
echo $go_test_cmd
42+
$go_test_cmd
43+
if [ $? -ne 0 ]; then
44+
printf "[GO TEST FILED] ${go_test_cmd}"
45+
exit 1
46+
fi
47+
done

scripts/delta-test.sh

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,40 @@
11
#!/bin/bash
22

33
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 ' '`
1510
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"
3416
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"
4118

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
5240
done

scripts/dispacher-test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
pr_id=${PR_ID}
4+
5+
if [ -f ".changelog/${pr_id}.txt" ]; then
6+
make changelogtest
7+
8+
if [ $? -ne 0 ]; then
9+
printf "COMMIT FAILED\n"s
10+
exit 1
11+
fi
12+
exit 0
13+
fi
14+
15+
make deltatest
16+
if [ $? -ne 0 ]; then
17+
printf "COMMIT FAILED\n"
18+
exit 1
19+
fi

0 commit comments

Comments
 (0)