-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_finder.sh
executable file
·117 lines (100 loc) · 5.65 KB
/
test_finder.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
#!/bin/bash
set -e
OSD_BUILD_MANIFEST='../local-test-cluster/opensearch-dashboards-*/manifest.yml'
OSD_TEST_PATH='cypress/integration/core-opensearch-dashboards'
OSD_PLUGIN_TEST_PATH='cypress/integration/plugins'
TEST_TYPE=$OPTION
CI_GROUP_PATTERN_PREFIX="OpenSearch-Dashboards-ci-group-"
# Map component name in opensearch-build repo INPUT_MANIFEST with folder name for tests in functional repo
OSD_COMPONENT_TEST_MAP=( "OpenSearch-Dashboards:opensearch-dashboards"
"alertingDashboards:alerting-dashboards-plugin"
"anomalyDetectionDashboards:anomaly-detection-dashboards-plugin"
"ganttChartDashboards:gantt-chart-dashboards"
"indexManagementDashboards:index-management-dashboards-plugin"
"observabilityDashboards:observability-dashboards"
"queryWorkbenchDashboards:query-workbench-dashboards"
"reportsDashboards:reports-dashboards"
"securityDashboards:security"
"notificationsDashboards:notifications-dashboards"
"customImportMapDashboards:custom-import-map-dashboards"
"searchRelevanceDashboards:search-relevance-dashboards"
"mlCommonsDashboards:ml-commons-dashboards"
"securityAnalyticsDashboards:security-analytics-dashboards-plugin"
"assistantDashboards:dashboards-assistant"
"OpenSearch-Dashboards-ci-group-1:OpenSearch-Dashboards-ci-group-1"
"OpenSearch-Dashboards-ci-group-2:OpenSearch-Dashboards-ci-group-2"
"OpenSearch-Dashboards-ci-group-3:OpenSearch-Dashboards-ci-group-3"
"OpenSearch-Dashboards-ci-group-4:OpenSearch-Dashboards-ci-group-4"
"OpenSearch-Dashboards-ci-group-5:OpenSearch-Dashboards-ci-group-5"
"OpenSearch-Dashboards-ci-group-6:OpenSearch-Dashboards-ci-group-6"
"OpenSearch-Dashboards-ci-group-7:OpenSearch-Dashboards-ci-group-7"
"OpenSearch-Dashboards-ci-group-8:OpenSearch-Dashboards-ci-group-8"
"OpenSearch-Dashboards-ci-group-9:OpenSearch-Dashboards-ci-group-9"
)
if [ -z $TEST_TYPE ]; then
[ -f $OSD_BUILD_MANIFEST ] && TEST_TYPE="manifest" || TEST_TYPE="default"
fi
if [ `echo $OSTYPE | grep -i 'linux'` ] || [ `echo $OSTYPE | grep -i 'darwin'` ]
then
[ ! `echo $SHELL | grep -i 'bash'` ] && echo "You must run this script with bash as other shells like zsh will fail the script, exit in 10!" && sleep 10 && exit 1
else
[ ! `readlink /proc/$$/exe | grep -i 'bash'` ] && echo "You must run this script with bash as other shells like zsh will fail the script, exit in 10!!" && sleep 10 && exit 1
fi
# Checks if build manifest in parent directory of current directory under local-test-cluster/opensearch-dashboards-*
# When the test script executed in the CI, it scales up OpenSearch Dashboards under local-test-cluster with a
# manifest that contains the existing components.
#
# If the build manifest exists in the expected path then we can read the components to execute component tests if the
# component exists. If the build manifest does not exist then we can just use a default list of tests.
#
# Usages: get_test_list - Get all test list in the repository by default. If manifest exists, then only components in manifests will be added in test list
# get_test_list <component1> <component2> ... - Get test list based on user defined components. Ex: get_test_list OpenSearch-Dashboards reportsDashboards
function get_test_list() {
local TEST_FILES_LOCAL=""
local TEST_FILES_EXT_LOCAL=""
local TEST_PATH_LOCAL=""
local TEST_COMPONENTS_LOCAL="$@"
for map_entry in "${OSD_COMPONENT_TEST_MAP[@]}"; do
component_name=${map_entry%%:*}
test_folder=${map_entry#*:}
if [ "$component_name" = "OpenSearch-Dashboards" ]; then
TEST_PATH_LOCAL=$OSD_TEST_PATH
TEST_FILES_EXT_LOCAL="**/*.js"
else
TEST_PATH_LOCAL=$OSD_PLUGIN_TEST_PATH
TEST_FILES_EXT_LOCAL="*"
fi
if [ "$TEST_TYPE" = "default" ]; then
if [ -z "$TEST_COMPONENTS_LOCAL" ]; then
TEST_FILES_LOCAL+="$TEST_PATH_LOCAL/$test_folder/$TEST_FILES_EXT_LOCAL,"
else
for test_component in $TEST_COMPONENTS_LOCAL; do
if [ "$test_component" = "$component_name" ]; then
ci_group_pattern="${CI_GROUP_PATTERN_PREFIX}*"
if [[ $test_component == $ci_group_pattern ]]; then
group=${test_component#${CI_GROUP_PATTERN_PREFIX}}
TEST_FILES_LOCAL=`ci_grouped_specs_finder ${group}`
else
TEST_FILES_LOCAL+="$TEST_PATH_LOCAL/$test_folder/$TEST_FILES_EXT_LOCAL,"
fi
break
fi
done
fi
elif [ "$TEST_TYPE" = "manifest" ]; then
if grep -q $component_name $OSD_BUILD_MANIFEST; then
TEST_FILES_LOCAL+="$TEST_PATH_LOCAL/$test_folder/$TEST_FILES_EXT_LOCAL,"
fi
fi
done
echo "${TEST_FILES_LOCAL%,}"
}
function ci_grouped_specs_finder {
group=$1
IFS="," read -a SPEC_ARRAY <<< "$(npm run -s osd:ciGroup${group})"
FORMATTED_SPEC=""
for i in "${SPEC_ARRAY[@]}"; do
FORMATTED_SPEC+="${OSD_TEST_PATH}/opensearch-dashboards/${i},"
done
echo "${FORMATTED_SPEC}"
}