Skip to content

Commit 7c41234

Browse files
load yaml tests from same branch as client
1 parent 7314645 commit 7c41234

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.buildkite/run-repository.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ echo -e "\033[34;1mINFO:\033[0m TEST_SUITE ${TEST_SUITE}\033[0m"
2121
echo -e "\033[34;1mINFO:\033[0m NOX_SESSION ${NOX_SESSION}\033[0m"
2222
echo -e "\033[34;1mINFO:\033[0m PYTHON_VERSION ${PYTHON_VERSION}\033[0m"
2323
echo -e "\033[34;1mINFO:\033[0m PYTHON_CONNECTION_CLASS ${PYTHON_CONNECTION_CLASS}\033[0m"
24+
echo -e "\033[34;1mINFO:\033[0m YAML_TESTS_BRANCH ${YAML_TESTS_BRANCH}\033[0m"
2425

2526
echo -e "\033[1m>>>>> Build [elastic/elasticsearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
2627

.buildkite/run-tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export STACK_VERSION="${STACK_VERSION:=8.0.0-SNAPSHOT}"
99
export TEST_SUITE="${TEST_SUITE:=platinum}"
1010
export PYTHON_VERSION="${PYTHON_VERSION:=3.14}"
1111
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
12+
export YAML_TESTS_BRANCH=${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=main}
1213

1314
script_path=$(dirname $(realpath $0))
1415
source $script_path/functions/imports.sh

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import json
2626
import os
2727
import re
28+
import subprocess
2829
import warnings
2930
import zipfile
3031
from typing import Tuple, Union
@@ -35,6 +36,7 @@
3536

3637
from elasticsearch import ApiError, ElasticsearchWarning, RequestError
3738
from elasticsearch._sync.client.utils import _base64_auth_header
39+
from elasticsearch._version import __versionstr__
3840
from elasticsearch.compat import string_types
3941

4042
# some params had to be changed in python, keep track of them so we can rename
@@ -499,12 +501,28 @@ def remove_implicit_resolver(cls, tag_to_remove):
499501
# Construct the HTTP and Elasticsearch client
500502
http = urllib3.PoolManager(retries=urllib3.Retry(total=10))
501503

502-
yaml_tests_url = (
503-
"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/main"
504-
)
504+
branch_candidates = []
505+
if "YAML_TESTS_BRANCH" in os.environ:
506+
branch_candidates.append(os.environ["YAML_TESTS_BRANCH"] or "main")
507+
git_branch = subprocess.getoutput("git branch --show-current")
508+
if git_branch not in branch_candidates:
509+
branch_candidates.append(git_branch)
510+
package_version = __versionstr__.rsplit(".", 1)[0]
511+
if package_version not in branch_candidates:
512+
branch_candidates.append(package_version)
513+
if "main" not in branch_candidates:
514+
branch_candidates.append("main")
515+
516+
response = None
517+
for branch in branch_candidates:
518+
yaml_tests_url = f"https://api.github.com/repos/elastic/elasticsearch-clients-tests/zipball/{branch}"
519+
response = http.request("GET", yaml_tests_url)
520+
if response.status != 404:
521+
break
522+
assert response is not None
505523

506524
# Download the zip and start reading YAML from the files in memory
507-
package_zip = zipfile.ZipFile(io.BytesIO(http.request("GET", yaml_tests_url).data))
525+
package_zip = zipfile.ZipFile(io.BytesIO(response.data))
508526

509527
for yaml_file in package_zip.namelist():
510528
if not re.match(r"^.*\/tests\/.*\.ya?ml$", yaml_file):
@@ -549,7 +567,7 @@ def remove_implicit_resolver(cls, tag_to_remove):
549567
for prefix in ("rest-api-spec/", "test/", "free/", "platinum/"):
550568
if pytest_test_name.startswith(prefix):
551569
pytest_test_name = pytest_test_name[len(prefix) :]
552-
pytest_param_id = "%s[%d]" % (pytest_test_name, test_number)
570+
pytest_param_id = "[%s]%s[%d]" % (branch, pytest_test_name, test_number)
553571

554572
pytest_param = {
555573
"setup": setup_steps,

0 commit comments

Comments
 (0)