Skip to content

Commit e96003b

Browse files
Migrate TestCoreListDeprecatedPlatformWithInstalledJson from test_core.py to core_test.go
1 parent 0a4d3da commit e96003b

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

internal/integrationtest/core/core_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,40 @@ func TestCoreListSortedResults(t *testing.T) {
713713
require.True(t, strings.HasSuffix(platform, strings.TrimLeft(notSortedDeprecated, "[")))
714714

715715
}
716+
717+
func TestCoreListDeprecatedPlatformWithInstalledJson(t *testing.T) {
718+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
719+
defer env.CleanUp()
720+
721+
// Set up the server to serve our custom index file
722+
testIndex := paths.New("..", "testdata", "test_index.json")
723+
url := env.HTTPServeFile(8000, testIndex)
724+
725+
// update custom index
726+
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
727+
require.NoError(t, err)
728+
729+
// install some core for testing
730+
_, _, err = cli.Run("core", "install", "Package:x86", "--additional-urls="+url.String())
731+
require.NoError(t, err)
732+
733+
installedJsonFile := cli.DataDir().Join("packages", "Package", "hardware", "x86", "1.2.3", "installed.json")
734+
require.FileExists(t, installedJsonFile.String())
735+
lines, err := installedJsonFile.ReadFileAsLines()
736+
require.NoError(t, err)
737+
var json []byte
738+
for i, v := range lines {
739+
if i != 13 {
740+
json = append(json, []byte(v+"\n")...)
741+
}
742+
}
743+
err = installedJsonFile.WriteFile(json)
744+
require.NoError(t, err)
745+
746+
// test same behaviour with json output
747+
stdout, _, err := cli.Run("core", "list", "--additional-urls="+url.String(), "--format=json")
748+
require.NoError(t, err)
749+
750+
requirejson.Len(t, stdout, 1)
751+
requirejson.Query(t, stdout, ".[] | .deprecated", "true")
752+
}

test/test_core.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,6 @@ def test_core_search_update_index_delay(run_command, data_dir):
9393
assert "Downloading index" not in res.stdout
9494

9595

96-
def test_core_list_deprecated_platform_with_installed_json(run_command, httpserver, data_dir):
97-
# Set up the server to serve our custom index file
98-
test_index = Path(__file__).parent / "testdata" / "test_index.json"
99-
httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text())
100-
101-
# update custom index
102-
url = httpserver.url_for("/test_index.json")
103-
assert run_command(["core", "update-index", f"--additional-urls={url}"])
104-
105-
# install some core for testing
106-
assert run_command(["core", "install", "Package:x86", f"--additional-urls={url}"])
107-
108-
installed_json_file = Path(data_dir, "packages", "Package", "hardware", "x86", "1.2.3", "installed.json")
109-
assert installed_json_file.exists()
110-
installed_json = json.load(installed_json_file.open("r"))
111-
platform = installed_json["packages"][0]["platforms"][0]
112-
del platform["deprecated"]
113-
installed_json["packages"][0]["platforms"][0] = platform
114-
with open(installed_json_file, "w") as f:
115-
json.dump(installed_json, f)
116-
117-
# test same behaviour with json output
118-
result = run_command(["core", "list", f"--additional-urls={url}", "--format=json"])
119-
assert result.ok
120-
121-
platforms = json.loads(result.stdout)
122-
assert len(platforms) == 1
123-
assert platforms[0]["deprecated"]
124-
125-
12696
def test_core_list_platform_without_platform_txt(run_command, data_dir):
12797
assert run_command(["update"])
12898

0 commit comments

Comments
 (0)