-
Notifications
You must be signed in to change notification settings - Fork 4
/
run-tests.sh
692 lines (601 loc) · 24.2 KB
/
run-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#!/bin/bash -e
#
# Jenkins launch script.
# Use:
# bash run-tests.sh 'namespace1 namespace2 ...' [--service=fence] [--testedEnv=testedEnv] [--isGen3Release=isGen3Release] [--seleniumTimeout] [--selectedTest=selectedTest] [--selectedTag=selectedTag] [--debug=debug]
#
set -xe
help() {
cat - <<EOM
Jenkins test launch script. Assumes the GEN3_HOME environment variable
references a current [cloud-automation](https://github.com/uc-cdis/cloud-automation) folder.
Use:
bash run-tests.sh [[--namespace=]KUBECTL_NAMESPACE] [--service=service] [--testedEnv=testedEnv] [--isGen3Release=isGen3Release] [--selectedTest=selectedTest] [--selectedTag=selectedTag] [--dryrun] [--debug=debug]
--namespace default is KUBECTL_NAMESPACE:-default
--service default is service:-none
--testedEnv default is testedEnv:-none (for cdis-manifest PRs, specifies which environment is being tested, to know which tests are relevant)
--isGen3Release default is "false"
--seleniumTimeout default is 3600
--selectedTest default is selectedTest:-none
--selectedTag default is selectedTag:-none
--debug default is "false" (run tests in debug mode if true)
EOM
}
isDryRun=false
dryrun() {
local command
command="$@"
if [[ "$isDryRun" == false ]]; then
echo "Running: $command" 1>&2
eval "$command"
else
echo "DryRun - not running: $command" 1>&2
fi
}
# Check if a service in the manifest
ifServiceDeployed() {
local command
local response
command="g3kubectl get configmap manifest-versions -o json | jq -r .data.json | jq -r "'".[\"$1\"]"'""
response=$(eval "$command")
echo $response
}
# Takes one argument, being service name
getServiceVersion() {
local command
local response
local version
command="g3kubectl get configmap manifest-versions -o json | jq -r .data.json | jq -r "'".[\"$1\"]"'""
response=$(eval "$command")
# Get last item of delimited string using string operators:
# https://www.linuxjournal.com/article/8919
version=${response##*:}
echo $version
}
# Takes 3 required and 1 optional arguments:
# $1 test tag to avoid until service version is greater than last arg
# $2 service name
# $3 version of service where tests apply >=
# $4 version of service where tests apply >=, in monthly release (2020.xx) format
#
# ex: runTestsIfServiceVersion "@multipartupload" "fence" "3.0.0"
# or: runTestsIfServiceVersion "@multipartupload" "fence" "3.0.0" "2020.01"
runTestsIfServiceVersion() {
# make sure args provided
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
return 0
fi
local currentVersion
currentVersion=$(getServiceVersion $2)
# check if currentVersion is actually a number
# NOTE: this assumes that all releases are tagged with actual numbers like:
# 2.8.0, 3.0.0, 3.0, 0.2, 0.2.1.5, etc
re='[0-9]+([.][0-9])+'
if ! [[ $currentVersion =~ $re ]] ; then
# force non-version numbers (e.g. branches and master)
# to be some arbitrary large number, so that it will
# cause next comparison to run the optional test.
# NOTE: The assumption here is that branches and master should run all the tests,
# if you've branched off an old version that actually should NOT run the tests..
# this script cannot currently handle that
# hopefully our service versions are never "OVER 9000!"
versionAsNumber=9000
else
# version is actually a pinned number, not a branch name or master
versionAsNumber=$currentVersion
fi
min=$(printf "2020\n$versionAsNumber\n" | sort -V | head -n1)
if [[ "$min" = "2020" && -n "$4" ]]; then
# 1. versionAsNumber >=2020, so assume it is a monthly release (or it was a branch
# and is now 9000, in which case it will still pass the check as expected)
# 2. monthly release version arg was provided
# So, do the version comparison based on monthly release version arg
min=$(printf "$4\n$versionAsNumber\n" | sort -V | head -n1)
if [ "$min" = "$4" ]; then
echo "RUNNING $1 tests b/c $2 version ($currentVersion) is greater than $4"
else
echo "SKIPPING $1 tests b/c $2 version ($currentVersion) is less than $4"
donot $1
fi
else
# versionAsNumber is normal semver tag
min=$(printf "$3\n$versionAsNumber\n" | sort -V | head -n1)
if [ "$min" = "$3" ]; then
echo "RUNNING $1 tests b/c $2 version ($currentVersion) is greater than $3"
else
echo "SKIPPING $1 tests b/c $2 version ($currentVersion) is less than $3"
donot $1
fi
fi
}
# little helper to maintain doNotRunRegex
donot() {
local or
if [[ -z "$1" ]]; then
return 0
fi
or='|'
if [[ -z "$doNotRunRegex" ]]; then
or=''
fi
doNotRunRegex="${doNotRunRegex}${or}$1"
doNotRunRegexDotStar="${doNotRunRegexDotStar}${or}.*$1"
}
doNotRunRegex=""
# for advanced grep usage
doNotRunRegexDotStar=""
#----------------------------------------------------
# main
#
if [[ -z "$GEN3_HOME" ]]; then
echo "ERROR: GEN3_HOME environment not set - should reference cloud-automation/"
exit 1
fi
source "${GEN3_HOME}/gen3/lib/utils.sh"
gen3_load "gen3/gen3setup"
namespaceName="${KUBECTL_NAMESPACE}"
service="${service:-""}"
testedEnv="${testedEnv:-""}"
isGen3Release="${isGen3Release:false}"
seleniumTimeout="${seleniumTimeout:3600}"
selectedTest="${selectedTest:-""}"
selectedTag="${selectedTag:-""}"
debug="${debug:false}"
while [[ $# -gt 0 ]]; do
key="$(echo "$1" | sed -e 's/^-*//' | sed -e 's/=.*$//')"
value="$(echo "$1" | sed -e 's/^.*=//')"
case "$key" in
help)
help
exit 0
;;
service)
service="$value"
;;
namespace)
namespaceName="$value"
;;
testedEnv)
testedEnv="$value"
;;
isGen3Release)
isGen3Release="$value"
;;
seleniumTimeout)
seleniumTimeout="$value"
;;
selectedTest)
selectedTest="$value"
;;
selectedTag)
selectedTag="$value"
;;
dryrun)
isDryRun=true
;;
debug)
debug="$value"
;;
*)
if [[ -n "$value" && "$value" == "$key" ]]; then
# treat dangling option as namespace for backward compatability
namespaceName="$value"
else
echo "ERROR: unknown option $1"
help
exit 1
fi
;;
esac
shift
done
if [[ -z "$namespaceName" || -z "$service" ]]; then
echo "USE: --namespace=NAME and --service=SERVICE are required arguments"
help
exit 0
fi
if [[ -z "$KUBECTL_NAMESPACE" ]]; then
# namespace key for g3kubectl
KUBECTL_NAMESPACE="$namespaceName"
fi
if [[ "$KUBECTL_NAMESPACE" != "$namespaceName" ]]; then
echo -e "$(red_color "ERROR: KUBECTL_NAMESPACE environment does not match --namespace option: $KUBECTL_NAMESPACE != $namespaceName")\n"
help
exit 1
fi
if [[ "$JENKINS_HOME" != "" && "$RUNNING_LOCAL" == "false" ]]; then
# Set HOME environment variable as the current PR workspace
# to avoid conflicts between gen3 CLI (cdis-data-client) profile configurations
export HOME=$WORKSPACE
fi
cat - <<EOM
Running with:
namespace=$namespaceName
service=$service
testedEnv=$testedEnv
isGen3Release=$isGen3Release
seleniumTimeout=$seleniumTimeout
selectedTest=$selectedTest
selectedTag=$selectedTag
EOM
echo 'INFO: installing dependencies'
if [ -f gen3-qa-mutex.marker ]; then
echo "parallel-testing is enabled, the dependencies have already been installed by Jenkins."
export PARALLEL_TESTING_ENABLED="true"
else
dryrun npm ci
fi
################################ Disable Test Tags #####################################
runTestsIfServiceVersion "@multipartUpload" "fence" "2.8.0"
runTestsIfServiceVersion "@multipartUploadFailure" "fence" "3.0.0"
runTestsIfServiceVersion "@centralizedAuth" "fence" "3.0.0"
runTestsIfServiceVersion "@dbgapSyncing" "fence" "3.0.0"
runTestsIfServiceVersion "@indexRecordConsentCodes" "sheepdog" "1.1.13"
runTestsIfServiceVersion "@coreMetadataPage" "portal" "2.20.8"
runTestsIfServiceVersion "@indexing" "portal" "2.26.0" "2020.05"
runTestsIfServiceVersion "@cleverSafe" "fence" "4.22.4" "2020.09"
runTestsIfServiceVersion "@requestor" "requestor" "1.5.0" "2022.02"
runTestsIfServiceVersion "@requestor" "arborist" "3.2.0" "2021.12"
runTestsIfServiceVersion "@requestorNew" "requestor" "1.5.1" "2022.06"
runTestsIfServiceVersion "@requestorNew" "arborist" "3.2.0" "2021.12"
runTestsIfServiceVersion "@requestorRoleIds" "requestor" "1.7.0" "2022.09"
runTestsIfServiceVersion "@requestorRoleIds" "arborist" "3.2.0" "2021.12"
runTestsIfServiceVersion "@clientCreds" "arborist" "4.0.0" "2022.12"
runTestsIfServiceVersion "@clientCreds" "fence" "6.1.0" "2022.10"
runTestsIfServiceVersion "@clientCreds" "requestor" "1.8.0" "2022.12"
runTestsIfServiceVersion "@clientExpiration" "fence" "7.0.0" "2023.01"
runTestsIfServiceVersion "@clientRotation" "fence" "8.0.0" "2023.06"
# disable tests if the service is not deployed
# export isIndexdDeployed=$(ifServiceDeployed "indexd")
# if [ -z "$isIndexdDeployed" ] || [ "$isIndexdDeployed" = "null" ];then
# echo "indexd is not deployed.Skip all tests required indexd.."
# donot '@requires-indexd'
# fi
listVar="arborist fence guppy indexd manifestservice metadata pelican peregrine pidgin portal sheepdog sower tube audit-service requestor hatchery argo-wrapper cohort-middleware dicom-viewer dicom-server"
for svc_name in $listVar; do
export isServiceDeployed=$(ifServiceDeployed $svc_name)
if [ -z "$isServiceDeployed" ] || [ "$isServiceDeployed" = "null" ]; then
echo "$svc_name is not deployed.Skip all tests requiring $svc_name.."
echo "@requires-$svc_name"
donot "@requires-$svc_name"
fi
done
# environments that use DCF features
# we only run Google Data Access tests for cdis-manifest PRs to these
envsRequireGoogle="dcp.bionimbus.org internalstaging.theanvil.io staging.theanvil.io gen3.theanvil.io preprod.gen3.biodatacatalyst.nhlbi.nih.gov staging.gen3.biodatacatalyst.nhlbi.nih.gov gen3.biodatacatalyst.nhlbi.nih.gov nci-crdc-staging.datacommons.io nci-crdc.datacommons.io"
#
# DataClientCLI tests require a fix to avoid parallel test runs
# contending over config files in the home directory
#
donot '@dataClientCLI'
# Do not run performance testing
donot '@Performance'
# Do not run manual tests
donot '@manual'
# Do not run force-fail tests
donot '@fail'
# Do not run batch processing tests
donot '@batch'
# Do not run prjsBucketAccess (for prod-execution only)
donot '@prjsBucketAccess'
echo "INFO: disabling RAS DRS test as jenkins env is not configured"
donot '@rasDRS'
# For dataguids.org PRs, skip all fence-related bootstrapping oprations
# as the environment does not have fence
if [ "$testedEnv" == "dataguids.org" ]; then
# disable bootstrap script from codeceptjs
sed -i '/bootstrap\:/d' codecept.conf.js
sed -i '/bootstrap\:/d' gen3.qa.in.a.box.codecept.conf.js
else
# skip dataguids tests for PRs other than dataguids.org manifest PRs
donot '@dataguids'
fi
#
# Google Data Access tests are only required for some envs
#
if [[ "$isGen3Release" != "true" && "$service" != "gen3-qa" && "$service" != "fence" && !("$service" == "cdis-manifest" && $envsRequireGoogle =~ (^| )$testedEnv($| )) ]]; then
# run all tests except for those that require google configuration
echo "INFO: disabling Google Data Access tests for $service"
donot '@reqGoogle'
else
#
# Run tests including google backend
#
echo "INFO: enabling Google Data Access tests for $service"
fi
# gen3-client tests run on gen3-qa repo and in nightly builds
if [[ "$service" != "gen3-qa" && "$service" != "cdis-data-client" && "$service" != "gen3-client" ]]; then
donot '@gen3-client'
fi
echo "INFO: temporarily disabling GWAS UI tests as jenkins envs are not still configured"
donot '@GWASUI'
#
# RAS AuthN Integration tests are only required for some repos
#
if [[ "$isGen3Release" != "true" && "$service" != "gen3-qa" && "$service" != "fence" && "$service" != "cdis-manifest" && "$service" != "gitops-qa" && "$service" != "cloud-automation" && "$service" != "gitops-dev" ]]; then
# disable ras tests
echo "INFO: disabling RAS AuthN Integration tests for $service"
donot '@rasAuthN'
else
#
# Run tests including RAS AuthN Integration tests
# If RAS Staging is down, uncomment the line below to skip these tests
# donot '@rasAuthN'
runTestsIfServiceVersion "@rasAuthN" "fence" "4.22.1" "2020.09"
echo "INFO: enabling RAS AuthN Integration tests for $service"
donot '@rasAuthN'
# Disabling RAS tests temporarily because of RAS authentication issues
fi
# TODO: eventually enable for all services, but need arborist and fence updates first
# in all environments
if [[ "$service" == "cdis-manifest" ]]; then
echo "INFO: disabling Centralized Auth tests for $service"
donot '@centralizedAuth'
donot '@indexdJWT'
else
echo "INFO: enabling Centralized Auth tests for $service"
fi
# Only run register user tests in midrc
#if [[ !( "$service" =~ ^(cdis-manifest|gitops-qa|gen3-qa) && $testedEnv == *"midrc"* )]]; then
# echo "INFO: disabling Register User tests for $service"
# donot '@registerUser'
#else
# echo "INFO: enabling Register User tests for $service"
#fi
donot '@registerUser'
donot '@dicomViewer'
# Focus on GUI tests for data-portal
if [[ "$service" == "data-portal" ]]; then
echo "INFO: disabling tests involving RESTful APIs & Gen3 CLI / Batch operations for $service"
donot '@metadataIngestion'
fi
echo "Checking kubernetes for optional services to test"
if ! (g3kubectl get pods --no-headers -l app=spark | grep spark) > /dev/null 2>&1; then
donot '@etl'
fi
if ! (g3kubectl get pods --no-headers -l app=ssjdispatcher | grep ssjdispatcher) > /dev/null 2>&1; then
# do not run data upload tests if the data upload flow is not deployed
donot '@dataUpload'
fi
if ! (g3kubectl get pods --no-headers -l app=guppy | grep guppy) > /dev/null 2>&1; then
# do not run Guppy API tests if Guppy is not deployed
donot '@guppyAPI'
fi
if [[ -z "$TEST_DATA_PATH" ]]; then
echo "ERROR: TEST_DATA_PATH env var is not set--cannot find schema in run-tests.sh."
exit 1
fi
set +e
ddHasConsentCodes=$(jq -re '.|values|map(select(.data_file_properties.consent_codes!=null))|.[]' < "$TEST_DATA_PATH/schema.json")
set -e
if [ -z "$ddHasConsentCodes" ]; then
# do not run tests for consent codes in indexd records if the dictionary's data_file_properties doesn't have consent_codes
donot '@indexRecordConsentCodes'
fi
#### FRONTEND_ROOT ####
export frontend_root="$(g3kubectl get configmaps manifest-global -o yaml | yq '.data.frontend_root')"
if [[ $frontend_root == \"gen3ff\" ]]; then
export PORTAL_SUFFIX="/portal"
donot '@centralizedAuth'
else
export PORTAL_SUFFIX=""
donot '@requires-frontend-framework'
fi
#### GEN3 FF HEAL ####
if [[ ! $testedEnv == *"heal"* ]]; then
donot '@heal'
fi
#
# try to read configs of portal
#
hostname="$(g3kubectl get configmaps manifest-global -o json | jq -r '.data.hostname')"
portalApp="$(g3kubectl get configmaps manifest-global -o json | jq -r '.data.portal_app')"
portalConfigURL="https://${hostname}${PORTAL_SUFFIX}/data/config/${portalApp}.json"
portalVersion="$(g3kubectl get configmaps manifest-all -o json | jq -r '.data.json | fromjson.versions.portal')"
# do not run portal related tests for NDE portal
if [[ "$portalVersion" == *"data-ecosystem-portal"* ]]; then
donot '@portal'
fi
# do not run top bar login test if version of portal is old
# update the version once this change is released
if ! [[ "$portalVersion" == *"master" ]]; then
donot '@topBarLogin'
donot '@loginRedirect'
fi
# check if manifest indexing jobs are set in sower block
# this is a temporary measure while PXP-4796 is not implemented
set +e
checkForPresenceOfManifestIndexingSowerJob=$(g3kubectl get cm manifest-sower -o yaml | grep manifest-indexing)
set -e
if [ -z "$checkForPresenceOfManifestIndexingSowerJob" ]; then
echo "the manifest-indexing sower job was not found, skip @indexing tests";
donot '@indexing'
fi
set +e
checkForPresenceOfMetadataIngestionSowerJob=$(g3kubectl get cm manifest-sower -o yaml | grep get-dbgap-metadata)
set -e
if [ -z "$checkForPresenceOfMetadataIngestionSowerJob" ]; then
echo "the get-dbgap-metadata sower job was not found, skip @metadataIngestion tests";
donot '@metadataIngestion'
fi
# # Study Viewer test
# runStudyViewerTests=false
# #run for data-portal/requestor/gen3-qa/gitops-qa/cdis-manifest repo
# if [[ ! ("$service" =~ ^(data-portal|requestor|gen3-qa)$ || $testedEnv == *"niaid"*) ]]; then
# echo "Disabling study-viewer test"
# donot "@studyViewer"
# else
# if [[ $(curl -s "$portalConfigURL" | jq 'contains({studyViewerConfig})') == "true" ]]; then
# if (g3kubectl get pods --no-headers -l app=requestor | grep requestor) > /dev/null 2>&1; then
# echo "### Study-Viewer is deployed"
# runStudyViewerTests=true
# fi
# fi
# fi
# disabling the studyViewer test for debugging
donot '@studyViewer'
# disabling the nondbgap usersync test as the jenkins is configured
donot '@nondbgapUsersyncTest'
# landing page buttons
if [[ $(curl -s "$portalConfigURL" | jq '.components | contains({buttons}) | not') == "true" ]] || [[ ! -z "$testedEnv" ]]; then
donot '@landing'
fi
if ! (g3kubectl get pods --no-headers -l app=manifestservice | grep manifestservice) > /dev/null 2>&1 ||
! (g3kubectl get pods --no-headers -l app=wts | grep wts) > /dev/null 2>&1; then
donot '@exportToWorkspaceAPI'
donot '@exportToWorkspacePortalGeneral'
donot '@exportToWorkspacePortalJupyterHub'
donot '@exportToWorkspacePortalHatchery'
elif [[ $(curl -s "$portalConfigURL" | jq 'contains({dataExplorerConfig: {buttons: [{enabled: true, type: "export-to-workspace"}]}}) | not') == "true" ]] ||
[[ ! -z "$testedEnv" ]]; then
# do not run export to workspace portal tests if not enabled or in a manifest PR
donot '@exportToWorkspacePortalGeneral'
donot '@exportToWorkspacePortalJupyterHub'
donot '@exportToWorkspacePortalHatchery'
elif ! (g3kubectl get pods --no-headers -l app=jupyter-hub | grep jupyterhub) > /dev/null 2>&1; then
donot '@exportToWorkspacePortalJupyterHub'
elif ! (g3kubectl get pods --no-headers -l app=hatchery | grep hatchery) > /dev/null 2>&1 ||
! (g3kubectl get pods --no-headers -l service=ambassador | grep ambassador) > /dev/null 2>&1; then
donot '@exportToWorkspacePortalHatchery'
fi
if [[ "$service" == "pelican" || "$service" == "tube" || "$service" == "cdis-manifest" || "$service" == "gen3-qa" || "$service" == "gitops-qa" ]]; then
echo "Running pfbExportTest since repo is $service"
else
echo "Skipping pfbExportTest since repo is $service"
donot '@pfbExport'
fi
donot '@jupyterNb'
#
# only run audit-service tests for manifest repos IF audit-service is
# deployed, and for repos with an audit-service integration.
#
runAuditTests=true
if ! [[ "$service" =~ ^(audit-service|fence|cloud-automation|gen3-qa)$ ]]; then
if [[ "$service" =~ ^(cdis-manifest|gitops-qa|gitops-dev)$ ]]; then
if ! (g3kubectl get pods --no-headers -l app=audit-service | grep audit-service) > /dev/null 2>&1; then
echo "INFO: audit-service is not deployed"
runAuditTests=false
fi
else
echo "INFO: no need to run audit-service tests for repo $service"
runAuditTests=false
fi
fi
if [[ "$runAuditTests" == true ]]; then
echo "INFO: enabling audit-service tests"
else
echo "INFO: disabling audit-service tests"
donot '@audit'
fi
# the tests assume audit-service can read from an AWS SQS
runTestsIfServiceVersion "@audit" "audit-service" "1.0.0" "2021.06"
# the tests assume fence records both successful and unsuccessful events
runTestsIfServiceVersion "@audit" "fence" "5.1.0" "2021.07"
#
# Run Agg MDS tests only if the feature is enabled
# and service is one of metadata-service, cdis-manifest, gitops-qa, gitops-dev and gen3-qa
# and if metadata service version is 1.5.0 (semver) / 2021.10 (monthly)
#
usingAggMDS=$(g3kubectl get cm manifest-metadata -o yaml | yq .data.USE_AGG_MDS)
portalUsingAggMDS=$(gen3 secrets decode portal-config gitops.json | jq '.featureFlags.discoveryUseAggMDS')
if ! [[ $usingAggMDS == \"true\" && $portalUsingAggMDS == "true" && "$service" =~ ^(cdis-manifest|gitops-qa|gitops-dev|gen3-qa|metadata-service) ]]; then
donot '@aggMDS'
fi
runTestsIfServiceVersion "@aggMDS" "metadata" "1.6.0" "2021.10"
#
# Run Discovery Page tests only if feature flag is enabled
# and service is one of metadata-service, cdis-manifest, gitops-qa, gitops-dev and gen3-qa
# and if portal service version is 3.8.1 (semver) / 2021.10 (monthly)
#
discoveryFeatureFlagEnabled=$(gen3 secrets decode portal-config gitops.json | jq '.featureFlags.discovery')
if ! [[ $discoveryFeatureFlagEnabled == "true" && "$service" =~ ^(cdis-manifest|gitops-qa|gitops-dev|gen3-qa|metadata-service) ]]; then
donot '@discoveryPage'
fi
runTestsIfServiceVersion "@discoveryPage" "portal" "3.8.1" "2021.09"
########################################################################################
testArgs="--reporter mocha-multi"
if [[ -n "$doNotRunRegex" ]]; then
testArgs="${testArgs} --grep '${doNotRunRegex}' --invert"
fi
exitCode=0
# set required vars
export NAMESPACE="$namespaceName"
if [[ "$testedEnv" == "ci-env-1.planx-pla.net" ]]; then
export GCLOUD_DYNAMIC_PROJECT="gen3qa-ci-env-1-279903"
fi
export testedEnv="$testedEnv"
#### Gen3 QA in a BOX ############################################################################
if [[ "$(hostname)" == *"cdis-github-org"* ]] || [[ "$(hostname)" == *"planx-ci-pipeline"* ]]; then
echo "inside an ephemeral gen3-qa-in-a-box pod..."
# Start selenium process within the ephemeral jenkins pod.
# npx selenium-standalone install --version=4.0.0-alpha-7 --drivers.chrome.version=96.0.4664.45 --drivers.chrome.baseURL=https://chromedriver.storage.googleapis.com
chromeVersion=$(google-chrome --version | grep -Eo '[0-9.]{10,20}' | cut -d '.' -f 1-3)
echo "Chrome Version: ${chromeVersion}"
# chromeDriverVersion=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$chromeVersion)
# npx selenium-standalone install --drivers.chrome.version=$chromeDriverVersion --drivers.chrome.baseURL=https://chromedriver.storage.googleapis.com
# timeout $seleniumTimeout npx selenium-standalone start --drivers.chrome.version=$chromeDriverVersion &
# gen3-qa-in-a-box requires a couple of changes to its webdriver config
set +e
mv gen3.qa.in.a.box.codecept.conf.js codecept.conf.js
cat codecept.conf.js
set -e
else
echo "NOT inside an ephemeral gen3-qa-in-a-box pod..."
fi
##################################################################################################
if [ "$selectedTest" == "all" ]; then
# no interactive tests
export GEN3_INTERACTIVE=false
cat - <<EOM
---------------------------
Launching test in $NAMESPACE
EOM
set +e
dryrun npm 'test' -- $testArgs
RC=$?
#
# Do this kind of thing (uncomment the following line, change the grep)
# to limit your test run in jenkins:
# dryrun npm 'test' -- --reporter mocha-multi --verbose --grep '@FRICKJACK'
exitCode=$RC
set -e
else
if [ -n "$selectedTest" ]; then
echo "Test selected - $selectedTest"
set +e
foundDataClientCLI=$(grep "@dataClientCLI" ${selectedTest})
if [ -n "$foundDataClientCLI" ]; then
donot '@indexRecordConsentCodes'
donot '@dataClientCLI'
fi
if [[ "$selectedTest" == "suites/sheepdogAndPeregrine/submitAndQueryNodesTest.js" && -z "$ddHasConsentCodes" ]]; then
donot '@indexRecordConsentCodes'
fi
dryrun REPO=$service DEBUG=$debug npm 'test' -- $testArgs ${selectedTest}
RC=$?
exitCode=$RC
set -e
fi
if [ -n "$selectedTag" ]; then
echo "Tag selected - $selectedTag"
REPO=$service DEBUG=$debug npm 'test' -- --reporter mocha-multi --verbose --grep "(?=.*$selectedTag)^(?!$doNotRunRegexDotStar)"
RC=$?
exitCode=$RC
set -e
fi
fi
# When zero tests are executed, a results*.xml file is produced containing a tests="0" counter
# e.g., output/result57f4d8778c4987bda6a1790eaa703782.xml
# <testsuites name="Mocha Tests" time="0.0000" tests="0" failures="0">
[ "$(ls -A output)" ] && ls output/result*.xml || echo "Warn: there are no output/result-*.xml files to parse"
set +e
cat output/result*.xml | head -n2 | sed -n -e 's/^<testsuites.*\(tests\=.*\) failures.*/\1/p'
zeroTests=$(cat output/result*.xml | head -n2 | sed -n -e 's/^<testsuites.*\(tests\=.*\) failures.*/\1/p' | grep "tests=\"0\"")
set -e
if [ -n "$zeroTests" ]; then
echo "No tests have been executed, aborting PR check..."
npm test -- --verbose suites/fail.js
exitCode=1
fi
echo "Testing done at $(date)" > output/gen3-qa.log
exit $exitCode