diff --git a/tests/README.md b/tests/README.md index a8f9bf47f..b26e71b38 100644 --- a/tests/README.md +++ b/tests/README.md @@ -17,8 +17,7 @@ programs. 2. The following programs must be installed: * `mysql` (the CLI client) - * `python2.7` - * `curl` + * `wget` * `openssl` 3. The user executing the tests must have permission to create the folder diff --git a/tests/_utils/run_curl b/tests/_utils/run_curl new file mode 100755 index 000000000..82c8f13d5 --- /dev/null +++ b/tests/_utils/run_curl @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Copyright 2020 PingCAP, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: run_curl https://url '{"json":"data"}' + +set -eu +TEST_DIR=/tmp/lightning_test_result + +if [ -z "${2-}" ]; then + POST_ARGS= +else + POST_ARGS="--post-data '$2'" +fi + +# FIXME: use `wget` instead of `curl` because the latter rejects ECC certs on our CI. +# CentOS is re~~ally old. +wget -q -O - \ + --ca-certificate="$TEST_DIR/tls/ca.pem" \ + --certificate="$TEST_DIR/tls/curl.pem" \ + --private-key="$TEST_DIR/tls/curl.key" \ + $POST_ARGS "$1" diff --git a/tests/check_requirements/run.sh b/tests/check_requirements/run.sh index 2ca2cd08a..601d5e3fc 100755 --- a/tests/check_requirements/run.sh +++ b/tests/check_requirements/run.sh @@ -16,11 +16,7 @@ set -eu curl_cluster_version() { - curl "$@" \ - --cacert "$TEST_DIR/tls/ca.pem" \ - --cert "$TEST_DIR/tls/curl.pem" \ - --key "$TEST_DIR/tls/curl.key" \ - 'https://127.0.0.1:2379/pd/api/v1/config/cluster-version' + run_curl 'https://127.0.0.1:2379/pd/api/v1/config/cluster-version' "$@" } # should be OK when the version is normal @@ -30,11 +26,11 @@ run_lightning --check-requirements=1 -L warning # now try to reduce the version to below 2.1.0 OLD_VERSION=$(curl_cluster_version) reset_cluster_version() { - curl_cluster_version --data-binary '{"cluster-version":'"$OLD_VERSION"'}' + curl_cluster_version '{"cluster-version":'"$OLD_VERSION"'}' } trap reset_cluster_version EXIT -curl_cluster_version --data-binary '{"cluster-version":"2.0.0-fake.and.error.expected"}' +curl_cluster_version '{"cluster-version":"2.0.0-fake.and.error.expected"}' run_sql 'DROP DATABASE IF EXISTS checkreq' set +e diff --git a/tests/run.sh b/tests/run.sh index ab81997da..274613b26 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -74,7 +74,7 @@ EOF bin/pd-server --config "$TEST_DIR/pd-config.toml" & # wait until PD is online... i=0 - while ! curl --cacert "$TT/ca.pem" --cert "$TT/curl.pem" --key "$TT/curl.key" -o /dev/null -sf https://127.0.0.1:2379/pd/api/v1/version; do + while ! run_curl https://127.0.0.1:2379/pd/api/v1/version; do i=$((i+1)) if [ "$i" -gt 10 ]; then echo 'Failed to start PD'