Skip to content

Commit 92ef3ad

Browse files
committed
[skip changelog] Integration tests index json is now served from local fileserver
1 parent fda79da commit 92ef3ad

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

poetry.lock

+36-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ flake8 = "^3.8.3"
1919
black = { version = "^19.10b0", allow-prereleases = true }
2020
filelock = "^3.0.12"
2121
pytest-xdist = "^2.1.0"
22+
pytest_httpserver = "^0.3.5"
2223

2324
[tool.black]
2425
line-length = 120

test/test_core.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
import platform
1717
import pytest
1818
import simplejson as json
19+
from pathlib import Path
1920

2021

21-
def test_core_search(run_command):
22-
url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
23-
assert run_command("core update-index --additional-urls={}".format(url))
22+
def test_core_search(run_command, httpserver):
23+
# Set up the server to serve our custom index file
24+
test_index = Path(__file__).parent / "testdata" / "test_index.json"
25+
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
26+
27+
url = httpserver.url_for("/test_index.json")
28+
assert run_command(f"core update-index --additional-urls={url}")
2429
# search a specific core
2530
result = run_command("core search avr")
2631
assert result.ok
@@ -41,15 +46,19 @@ def test_core_search(run_command):
4146
assert 2 == len(data)
4247

4348

44-
def test_core_search_no_args(run_command):
49+
def test_core_search_no_args(run_command, httpserver):
4550
"""
4651
This tests `core search` with and without additional URLs in case no args
4752
are passed (i.e. all results are shown).
4853
"""
54+
# Set up the server to serve our custom index file
55+
test_index = Path(__file__).parent / "testdata" / "test_index.json"
56+
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
57+
4958
# update custom index and install test core (installed cores affect `core search`)
50-
url = "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/test_index.json"
51-
assert run_command("core update-index --additional-urls={}".format(url))
52-
assert run_command("core install test:x86 --additional-urls={}".format(url))
59+
url = httpserver.url_for("/test_index.json")
60+
assert run_command(f"core update-index --additional-urls={url}")
61+
assert run_command(f"core install test:x86 --additional-urls={url}")
5362

5463
# list all with no additional urls, ensure the test core won't show up
5564
result = run_command("core search")
@@ -69,7 +78,7 @@ def test_core_search_no_args(run_command):
6978
assert len(platforms) == num_platforms
7079

7180
# list all with additional urls, check the test core is there
72-
result = run_command("core search --additional-urls={}".format(url))
81+
result = run_command(f"core search --additional-urls={url}")
7382
assert result.ok
7483
num_platforms = 0
7584
found = False
@@ -81,7 +90,7 @@ def test_core_search_no_args(run_command):
8190
assert found
8291

8392
# same thing in JSON format, also check the number of platforms found is the same
84-
result = run_command("core search --format json --additional-urls={}".format(url))
93+
result = run_command(f"core search --format json --additional-urls={url}")
8594
assert result.ok
8695
found = False
8796
platforms = json.loads(result.stdout)

0 commit comments

Comments
 (0)