Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test component selector to run specific tests #234

Merged
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
12 changes: 9 additions & 3 deletions integtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ function usage() {
echo -e "-p BIND_PORT\t, defaults to 9200 or 5601 depends on OpenSearch or Dashboards, can be changed to any port for the cluster location."
echo -e "-s SECURITY_ENABLED\t(true | false), defaults to true. Specify the OpenSearch/Dashboards have security enabled or not."
echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true."
echo -e "-t TEST_COMPONENTS\t(OpenSearch-Dashboards reportsDashboards etc.), optional, specify test components, separate with space, else test everything."
echo -e "-v VERSION\t, no defaults, indicates the OpenSearch version to test."
echo -e "-h\tPrint this message."
echo "--------------------------------------------------------------------------"
}

while getopts ":hb:p:s:c:v:" arg; do
while getopts ":hb:p:s:c:t:v:" arg; do
case $arg in
h)
usage
Expand All @@ -41,6 +42,9 @@ while getopts ":hb:p:s:c:v:" arg; do
c)
CREDENTIAL=$OPTARG
;;
t)
TEST_COMPONENTS=$OPTARG
;;
v)
VERSION=$OPTARG
;;
Expand Down Expand Up @@ -81,7 +85,9 @@ fi

npm install

TEST_FILES=$(get_test_list)
TEST_FILES=`get_test_list $TEST_COMPONENTS`
echo -e "Test Files List:"
echo $TEST_FILES | tr ',' '\n'

## WARNING: THIS LOGIC NEEDS TO BE THE LAST IN THIS FILE! ##
# Cypress returns back the test failure count in the error code
Expand All @@ -96,4 +102,4 @@ then
else
echo "run security disabled tests"
yarn cypress:run-without-security --browser chromium --spec "$TEST_FILES"
fi
fi
82 changes: 54 additions & 28 deletions test_finder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,69 @@ 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'

# 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"
)

[ -f $OSD_BUILD_MANIFEST ] && TEST_TYPE="manifest" || TEST_TYPE="default"
[ ! `echo $SHELL | grep '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

# 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() {
[ -f $OSD_BUILD_MANIFEST ] && generate_test_list_from_build_manifest || generate_test_list
}
local TEST_FILES_LOCAL=""
local TEST_FILES_EXT_LOCAL=""
local TEST_PATH_LOCAL=""
local TEST_COMPONENTS_LOCAL="$@"

function generate_test_list() {
DEFAULT_TEST_FILES="$OSD_TEST_PATH/opensearch-dashboards/*.js"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/alerting-dashboards-plugin/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/anomaly-detection-dashboards-plugin/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/gantt-chart-dashboards/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/index-management-dashboards-plugin/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/observability-dashboards/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/query-workbench-dashboards/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/reports-dashboards/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/security/*"
DEFAULT_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/notifications-dashboards/*"

echo "$DEFAULT_TEST_FILES"
}
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
TEST_FILES_LOCAL+="$TEST_PATH_LOCAL/$test_folder/$TEST_FILES_EXT_LOCAL,"
break
fi
done
fi

function generate_test_list_from_build_manifest() {
MANIFEST_TEST_FILES="$OSD_TEST_PATH/opensearch-dashboards/*.js"
elif [ "$TEST_TYPE" = "manifest" ]; then
if grep -q $component_name; then
TEST_FILES_LOCAL+="$TEST_PATH_LOCAL/$test_folder/$TEST_FILES_EXT_LOCAL,"
fi
fi

grep -q 'alertingDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/alerting-dashboards-plugin/*" || true
grep -q 'anomalyDetectionDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/anomaly-detection-dashboards-plugin/*" || true
grep -q 'ganttChartDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/gantt-chart-dashboards/*" || true
grep -q 'indexManagementDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/index-management-dashboards-plugin/*" || true
grep -q 'observabilityDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/observability-dashboards/*" || true
grep -q 'queryWorkbenchDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/query-workbench-dashboards/*" || true
grep -q 'reportsDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/reports-dashboards/*" || true
grep -q 'securityDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/security/*" || true
grep -q 'notificationsDashboards' $OSD_BUILD_MANIFEST && MANIFEST_TEST_FILES+=",$OSD_PLUGIN_TEST_PATH/notifications-dashboards/*" || true
done

echo "$MANIFEST_TEST_FILES"
echo "${TEST_FILES_LOCAL%,}"
}