1010DEFAULT_PACKAGE_TIMEOUT=" 45m"
1111
1212set -u
13+ set -e # Abort on errors
1314
1415if [ " ${1:- } " == " -m" ]; then
1516 echo " Running in automated master integration mode"
1617 # Set automated setting parameters
17- SG_COMMIT=" master"
1818 TARGET_PACKAGE=" ..."
1919 TARGET_TEST=" ALL"
2020 RUN_WALRUS=" true"
21- USE_GO_MODULES=" true"
2221 DETECT_RACES=" false"
2322 SG_EDITION=" EE"
24- XATTRS=" true"
2523 RUN_COUNT=" 1"
2624 # CBS server settings
2725 COUCHBASE_SERVER_PROTOCOL=" couchbase"
2826 COUCHBASE_SERVER_VERSION=" enterprise-7.6.6"
29- SG_TEST_BUCKET_POOL_SIZE=" 3"
30- SG_TEST_BUCKET_POOL_DEBUG=" true"
27+ export SG_TEST_BUCKET_POOL_DEBUG=" true"
3128 GSI=" true"
3229 TLS_SKIP_VERIFY=" false"
3330 SG_CBCOLLECT_ALWAYS=" false"
3431fi
3532
36- set -e # Abort on errors
37- set -x # Output all executed shell commands
33+ REQUIRED_VARS=(
34+ COUCHBASE_SERVER_PROTOCOL
35+ COUCHBASE_SERVER_VERSION
36+ GSI
37+ TARGET_TEST
38+ TARGET_PACKAGE
39+ TLS_SKIP_VERIFY
40+ SG_EDITION
41+ )
3842
43+ for var in " ${REQUIRED_VARS[@]} " ; do
44+ if [ -z " ${! var:- } " ]; then
45+ echo " ${var} environment variable is required to be set."
46+ exit 1
47+ fi
48+ done
3949# Use Git SSH and define private repos
4050git config --global --replace-all url.
" [email protected] :" .insteadOf
" https://github.com/" 4151export GOPRIVATE=github.com/couchbaselabs/go-fleecedelta
@@ -44,37 +54,21 @@ export GOPRIVATE=github.com/couchbaselabs/go-fleecedelta
4454SG_COMMIT_HASH=$( git rev-parse HEAD)
4555echo " Sync Gateway git commit hash: $SG_COMMIT_HASH "
4656
47- # Use Go modules (3.1 and above) or bootstrap for legacy Sync Gateway versions (3.0 and below)
48- if [ " ${USE_GO_MODULES:- } " == " false" ]; then
49- mkdir -p sgw_int_testing # Make the directory if it does not exist
50- cp bootstrap.sh sgw_int_testing/bootstrap.sh
51- cd sgw_int_testing
52- chmod +x bootstrap.sh
53- ./bootstrap.sh -c ${SG_COMMIT} -e ee
54- export GO111MODULE=off
55- go get -u -v github.com/tebeka/go2xunit
56- go get -u -v github.com/axw/gocov/gocov
57- go get -u -v github.com/AlekSi/gocov-xml
58- else
59- # Install tools to use
60- go install github.com/axw/gocov/gocov@latest
61- go install github.com/AlekSi/gocov-xml@latest
62- go install gotest.tools/gotestsum@latest
63- fi
57+ echo " Downloading tool dependencies..."
58+ go install github.com/axw/gocov/gocov@latest
59+ go install github.com/AlekSi/gocov-xml@latest
60+ go install gotest.tools/gotestsum@latest
6461
65- if [ " ${SG_TEST_X509:- } " == " true" -a " ${COUCHBASE_SERVER_PROTOCOL} " != " couchbases" ]; then
62+ if [ " ${SG_TEST_X509:- } " == " true" ] && [ " ${COUCHBASE_SERVER_PROTOCOL} " != " couchbases" ]; then
6663 echo " Setting SG_TEST_X509 requires using couchbases:// protocol, aborting integration tests"
6764 exit 1
6865fi
6966
7067# Set environment vars
71- GO_TEST_FLAGS=" -v -p 1 -count=${RUN_COUNT:- 1} "
68+ GO_TEST_FLAGS=( -v -p 1 " -count=${RUN_COUNT:- 1} " )
7269INT_LOG_FILE_NAME=" verbose_int"
7370
74- if [ -d " godeps" ]; then
75- export GOPATH=$( pwd) /godeps
76- fi
77- export PATH=$PATH :$( go env GOPATH) /bin:~ /go/bin
71+ export PATH=$PATH :~ /go/bin
7872echo " PATH: $PATH "
7973
8074if [ " ${TEST_DEBUG:- } " == " true" ]; then
@@ -83,38 +77,38 @@ if [ "${TEST_DEBUG:-}" == "true" ]; then
8377fi
8478
8579if [ " ${TARGET_TEST} " != " ALL" ]; then
86- GO_TEST_FLAGS= " ${GO_TEST_FLAGS} -run ${TARGET_TEST} "
80+ GO_TEST_FLAGS+=( -run " ${TARGET_TEST} " )
8781fi
8882
8983if [ " ${PACKAGE_TIMEOUT:- } " != " " ]; then
90- GO_TEST_FLAGS= " ${GO_TEST_FLAGS} -test.timeout=${PACKAGE_TIMEOUT} "
84+ GO_TEST_FLAGS+=( -test.timeout=" ${PACKAGE_TIMEOUT} " )
9185else
9286 echo " Defaulting package timeout to ${DEFAULT_PACKAGE_TIMEOUT} "
93- GO_TEST_FLAGS= " ${GO_TEST_FLAGS} -test.timeout=${DEFAULT_PACKAGE_TIMEOUT} "
87+ GO_TEST_FLAGS+=( -test.timeout=" ${DEFAULT_PACKAGE_TIMEOUT} " )
9488fi
9589
9690if [ " ${DETECT_RACES:- } " == " true" ]; then
97- GO_TEST_FLAGS=" ${GO_TEST_FLAGS} -race"
91+ GO_TEST_FLAGS=( -race)
9892fi
9993
10094if [ " ${FAIL_FAST:- } " == " true" ]; then
101- GO_TEST_FLAGS= " ${GO_TEST_FLAGS} -failfast"
95+ GO_TEST_FLAGS+=( -failfast)
10296fi
10397
10498if [ " ${SG_TEST_PROFILE_FREQUENCY:- } " == " true" ]; then
10599 export SG_TEST_PROFILE_FREQUENCY=${SG_TEST_PROFILE_FREQUENCY}
106100fi
107101
108102if [ " ${RUN_WALRUS} " == " true" ]; then
109- set +e
103+ set +e -x
104+ set -x +e
110105 # EE
111- gotestsum --junitfile=rosmar-ee.xml --junitfile-project-name rosmar-EE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ee.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode,cb_sg_enterprise $ GO_TEST_FLAGS github.com/couchbase/sync_gateway/${TARGET_PACKAGE} > verbose_unit_ee.out 2>&1
106+ gotestsum --junitfile=rosmar-ee.xml --junitfile-project-name rosmar-EE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ee.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode,cb_sg_enterprise " ${ GO_TEST_FLAGS[@]} " " github.com/couchbase/sync_gateway/${TARGET_PACKAGE} " > verbose_unit_ee.out 2>&1
112107 xmlstarlet ed -u ' //testcase/@classname' -x ' concat("rosmar-EE-", .)' rosmar-ee.xml > verbose_unit_ee.xml
113108 # CE
114- gotestsum --junitfile=rosmar-ce.xml --junitfile-project-name rosmar-CE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ce.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode $ GO_TEST_FLAGS github.com/couchbase/sync_gateway/${TARGET_PACKAGE} > verbose_unit_ce.out 2>&1
109+ gotestsum --junitfile=rosmar-ce.xml --junitfile-project-name rosmar-CE --junitfile-testcase-classname relative --format standard-verbose -- -coverprofile=coverage_walrus_ce.out -coverpkg=github.com/couchbase/sync_gateway/... -tags cb_sg_devmode " ${ GO_TEST_FLAGS[@]} " " github.com/couchbase/sync_gateway/${TARGET_PACKAGE} " > verbose_unit_ce.out 2>&1
115110 xmlstarlet ed -u ' //testcase/@classname' -x ' concat("rosmar-CE-", .)' rosmar-ce.xml > verbose_unit_ce.xml
116- set -e
117-
111+ set -e +x
118112fi
119113
120114# Run CBS
@@ -129,26 +123,26 @@ else
129123fi
130124
131125# Set up test environment variables for CBS runs
132- export SG_TEST_USE_XATTRS=${XATTRS}
133126export SG_TEST_USE_GSI=${GSI}
134127export SG_TEST_COUCHBASE_SERVER_URL=" ${COUCHBASE_SERVER_PROTOCOL} ://127.0.0.1"
135128export SG_TEST_BACKING_STORE=" Couchbase"
136- export SG_TEST_BUCKET_POOL_SIZE=${SG_TEST_BUCKET_POOL_SIZE}
137- export SG_TEST_BUCKET_POOL_DEBUG=${SG_TEST_BUCKET_POOL_DEBUG}
138129export SG_TEST_TLS_SKIP_VERIFY=${TLS_SKIP_VERIFY}
139130
140131if [ " ${SG_EDITION} " == " EE" ]; then
141- GO_TEST_FLAGS= " ${GO_TEST_FLAGS} -tags cb_sg_devmode,cb_sg_enterprise"
132+ GO_TEST_FLAGS+=( -tags " cb_sg_devmode,cb_sg_enterprise" )
142133else
143- GO_TEST_FLAGS= " ${GO_TEST_FLAGS} -tags cb_sg_devmode"
134+ GO_TEST_FLAGS+=( -tags cb_sg_devmode)
144135fi
145136
146- gotestsum --junitfile=integration.xml --junitfile-project-name integration --junitfile-testcase-classname relative --format standard-verbose -- ${GO_TEST_FLAGS} -coverprofile=coverage_int.out -coverpkg=github.com/couchbase/sync_gateway/... github.com/couchbase/sync_gateway/${TARGET_PACKAGE} 2>&1 | stdbuf -oL tee " ${INT_LOG_FILE_NAME} .out" | stdbuf -oL grep -a -E ' (--- (FAIL|PASS|SKIP):|github.com/couchbase/sync_gateway(/.+)?\t|TEST: |panic: )'
137+ set -x # Output all executed shell commands
138+ gotestsum --junitfile=integration.xml --junitfile-project-name integration --junitfile-testcase-classname relative --format standard-verbose -- " ${GO_TEST_FLAGS[@]} " -coverprofile=coverage_int.out -coverpkg=github.com/couchbase/sync_gateway/... " github.com/couchbase/sync_gateway/${TARGET_PACKAGE} " 2>&1 | stdbuf -oL tee " ${INT_LOG_FILE_NAME} .out" | stdbuf -oL grep -a -E ' (--- (FAIL|PASS|SKIP):|github.com/couchbase/sync_gateway(/.+)?\t|TEST: |panic: )'
147139if [ " ${PIPESTATUS[0]} " -ne " 0" ]; then # If test exit code is not 0 (failed)
148140 echo " Go test failed! Parsing logs to find cause..."
149141 TEST_FAILED=true
150142fi
151143
144+ set +x # Stop outputting all executed shell commands
145+
152146# Collect CBS logs if server error occurred
153147if [ " ${SG_CBCOLLECT_ALWAYS:- } " == " true" ] || grep -a -q " server logs for details\|Timed out after 1m0s waiting for a bucket to become available" " ${INT_LOG_FILE_NAME} .out" ; then
154148 docker exec -t couchbase /opt/couchbase/bin/cbcollect_info /workspace/cbcollect.zip
163157
164158# Get coverage
165159~ /go/bin/gocov convert " coverage_int.out" | ~ /go/bin/gocov-xml > coverage_int.xml
166- if [ " ${RUN_WALRUS} " == " true" ]; then
160+ if [ " ${RUN_WALRUS:- } " == " true" ]; then
167161 ~ /go/bin/gocov convert " coverage_walrus_ee.out" | ~ /go/bin/gocov-xml > " coverage_walrus_ee.xml"
168162 ~ /go/bin/gocov convert " coverage_walrus_ce.out" | ~ /go/bin/gocov-xml > " coverage_walrus_ce.xml"
169163fi
0 commit comments