Skip to content

Commit 75ef7ef

Browse files
committed
Refactored buildkite tests using run-elasticsearch
1 parent 761577e commit 75ef7ef

File tree

10 files changed

+63
-26
lines changed

10 files changed

+63
-26
lines changed

.buildkite/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ RUN composer install --no-progress > /dev/null
3939

4040
COPY . .
4141

42-
CMD ["bash", ".buildkite/yaml-tests.sh"]
42+
CMD ["bash", ".buildkite/yaml-tests.sh"]

.buildkite/pipeline.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ steps:
88
PHP_VERSION: "{{ matrix.php }}"
99
TEST_SUITE: "{{ matrix.suite }}"
1010
STACK_VERSION: 9.0.0-SNAPSHOT
11+
BRANCH_CLIENT_TESTS: 9.0
1112
matrix:
1213
setup:
1314
suite:
14-
- "stack"
15+
- "platinum"
1516
php:
1617
- "8.4-cli"
1718
- "8.3-cli"

.buildkite/run-repository.sh

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# TEST_SUITE -- which test suite to run: oss or xpack
66
# ELASTICSEARCH_URL -- The url at which elasticsearch is reachable, a default is composed based on STACK_VERSION and TEST_SUITE
77
# PHP_VERSION -- PHP version (defined in test-matrix.yml, a default is hardcoded here)
8-
# ES_LOCAL_PASSWORD -- The Elaticsarch password for the elastic user. Used for testing.
98
script_path=$(dirname $(realpath -s $0))
109
source $script_path/functions/imports.sh
1110
set -euo pipefail
@@ -19,11 +18,7 @@ echo -e "\033[34;1mINFO:\033[0m TEST_SUITE ${TEST_SUITE}\033[0m"
1918
echo -e "\033[34;1mINFO:\033[0m URL ${ELASTICSEARCH_URL}\033[0m"
2019
echo -e "\033[34;1mINFO:\033[0m CONTAINER ${elasticsearch_container}\033[0m"
2120
echo -e "\033[34;1mINFO:\033[0m PHP_VERSION ${PHP_VERSION}\033[0m"
22-
23-
echo -e "\033[1m>>>>> Running Elasticsearch >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
24-
25-
curl -fsSL https://elastic.co/start-local | sh -s -- -v ${STACK_VERSION} -esonly
26-
source elastic-start-local/.env
21+
echo -e "\033[34;1mINFO:\033[0m BRANCH_CLIENT_TESTS ${BRANCH_CLIENT_TESTS}\033[0m"
2722

2823
echo -e "\033[1m>>>>> Build docker container >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
2924

@@ -46,7 +41,8 @@ docker run \
4641
--env TEST_SUITE=${TEST_SUITE} \
4742
--env PHP_VERSION=${PHP_VERSION} \
4843
--env ELASTICSEARCH_URL=${ELASTICSEARCH_URL} \
44+
--env BRANCH_CLIENT_TESTS=${BRANCH_CLIENT_TESTS} \
4945
--ulimit nofile=65535:65535 \
5046
--name elasticsearch-php \
5147
--rm \
52-
elastic/elasticsearch-php
48+
elastic/elasticsearch-php

.buildkite/run-tests

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,17 @@ script_path=$(dirname $(realpath -s $0))
77
source $script_path/functions/imports.sh
88
set -euo pipefail
99

10+
echo "--- :elasticsearch: Starting Elasticsearch"
11+
DETACH=true bash $script_path/run-elasticsearch.sh
12+
13+
if [[ -n "$RUNSCRIPTS" ]]; then
14+
for RUNSCRIPT in ${RUNSCRIPTS//,/ } ; do
15+
echo -e "\033[1m>>>>> Running run-$RUNSCRIPT.sh >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
16+
CONTAINER_NAME=${RUNSCRIPT} \
17+
DETACH=true \
18+
bash $script_path/run-${RUNSCRIPT}.sh
19+
done
20+
fi
21+
1022
echo "+++ :php: Run Client"
11-
bash "$script_path/run-repository.sh"
23+
bash $script_path/run-repository.sh

.buildkite/yaml-tests.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env bash
22

33
# Clone the elasticsearch-clients-tests repository
4-
git clone https://github.com/elastic/elasticsearch-clients-tests.git tests/elasticsearch-clients-tests
4+
git clone -b ${BRANCH_CLIENT_TESTS} https://github.com/elastic/elasticsearch-clients-tests.git tests/elasticsearch-clients-tests
55

66
# Build the YAML tests
7-
php tests/build_es_tests.php tests/elasticsearch-clients-tests/tests ${TEST_SUITE} tests/Yaml
7+
php tests/build_es_tests.php tests/elasticsearch-clients-tests/tests stack tests/Yaml
88

99
# Run YAML tests
10-
ELASTICSEARCH_URL="http://elastic:${ES_LOCAL_PASSWORD}@localhost:9200" vendor/bin/phpunit -c "phpunit-yaml-${TEST_SUITE}-tests.xml"
10+
vendor/bin/phpunit -c "phpunit-yaml-stack-tests.xml"
11+
12+
# Remove Yaml tests
13+
rm -rf tests/Yaml
14+
15+
# Remove elasticsearch-clients-tests folder
16+
rm -rf tests/elasticsearch-clients-tests

.github/workflows/integration_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
- name: Integration tests
4848
run: |
4949
source elastic-start-local/.env
50-
ELASTICSEARCH_URL="http://elastic:${ES_LOCAL_PASSWORD}@localhost:9200" TEST_SUITE="platinum" composer run-script integration-test
50+
ELASTICSEARCH_URL="http://elastic:${ES_LOCAL_PASSWORD}@localhost:9200" TEST_SUITE="free" composer run-script integration-test

.github/workflows/yaml_test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
os: [ubuntu-latest]
1414
es-version: [9.0.0-SNAPSHOT]
1515
test-suite: [stack]
16+
branch-client-tests: [9.0]
1617

1718
steps:
1819
- name: Checkout
@@ -47,10 +48,10 @@ jobs:
4748
4849
- name: Build PHPUnit tests
4950
run: |
50-
git clone https://github.com/elastic/elasticsearch-clients-tests.git tests/elasticsearch-clients-tests
51+
git clone -b ${{ matrix.branch-client-tests }} https://github.com/elastic/elasticsearch-clients-tests.git tests/elasticsearch-clients-tests
5152
php tests/build_es_tests.php tests/elasticsearch-clients-tests/tests ${{ matrix.test-suite }} tests/Yaml
5253
5354
- name: YAML tests
5455
run: |
5556
source elastic-start-local/.env
56-
ELASTICSEARCH_URL="http://elastic:${ES_LOCAL_PASSWORD}@localhost:9200" vendor/bin/phpunit -c "phpunit-yaml-${{ matrix.test-suite }}-tests.xml"
57+
ELASTICSEARCH_URL="http://elastic:${ES_LOCAL_PASSWORD}@localhost:9200" TEST_SUITE="free" vendor/bin/phpunit -c "phpunit-yaml-${{ matrix.test-suite }}-tests.xml"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ util/cache/
2727
util/*.zip
2828
util/output/
2929
util/rest-spec
30+
elastic-start-local/
3031

3132
# Doctum docs generator
3233
/doctum.phar

src/ClientBuilder.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,10 @@ public function build(): Client
389389
}
390390

391391
/**
392-
* Elastic cloud optimized with gzip
392+
* Elastic cloud or serverless optimized with gzip
393393
* @see https://github.com/elastic/elasticsearch-php/issues/1241 omit for Symfony HTTP Client
394394
*/
395-
if ((!empty($this->cloudId) || $this->isCloudOrServerless($this->hosts)) && !$this->isSymfonyHttpClient($transport)) {
395+
if ((!empty($this->cloudId) || $this->isCloud($this->hosts) || $this->isServerless($this->hosts)) && !$this->isSymfonyHttpClient($transport)) {
396396
$transport->setHeader('Accept-Encoding', 'gzip');
397397
}
398398

@@ -404,19 +404,14 @@ public function build(): Client
404404
}
405405

406406
/**
407-
* Check if the hosts contains only one url and if it is from
408-
* Elastic Cloud or Serverless
407+
* Check if the hosts contains an Elastic Cloud url
409408
*/
410-
protected function isCloudOrServerless(array $hosts): bool
409+
protected function isCloud(array $hosts): bool
411410
{
412411
if (empty($hosts) || count($hosts)>1) {
413412
return false;
414413
}
415414
$url = $hosts[0];
416-
// Serverless
417-
if (preg_match('/\.elastic\.cloud/i', $url)) {
418-
return true;
419-
}
420415
// Elastic Cloud gcp
421416
if (preg_match('/\.cloud\.es\.io/i', $url)) {
422417
return true;
@@ -428,6 +423,21 @@ protected function isCloudOrServerless(array $hosts): bool
428423
return false;
429424
}
430425

426+
/**
427+
* Check if the hosts contains an Elastic Serverless url
428+
*/
429+
protected function isServerless(array $hosts): bool
430+
{
431+
if (empty($hosts) || count($hosts)>1) {
432+
return false;
433+
}
434+
$url = $hosts[0];
435+
if (preg_match('/\.elastic\.cloud/i', $url)) {
436+
return true;
437+
}
438+
return false;
439+
}
440+
431441
/**
432442
* Returns true if the transport HTTP client is Symfony
433443
*/

tests/Utility.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,26 @@ public static function getHost(): ?string
6767
if (false !== $url) {
6868
return $url;
6969
}
70-
return 'http://localhost:9200';
70+
if (getenv('TEST_SUITE') === 'free') {
71+
return 'http://localhost:9200';
72+
}
73+
return 'https://localhost:9200';
7174
}
7275

7376
/**
7477
* Build a Client based on ENV variables
7578
*/
7679
public static function getClient(): Client
7780
{
81+
if (getenv('TEST_SUITE') === 'free') {
82+
return ClientBuilder::create()
83+
->setHosts([self::getHost()])
84+
->build();
85+
}
7886
return ClientBuilder::create()
7987
->setHosts([self::getHost()])
88+
->setBasicAuthentication('elastic', 'changeme')
89+
->setSSLVerification(false)
8090
->build();
8191
}
8292

0 commit comments

Comments
 (0)