Skip to content

Commit 6afbd7f

Browse files
Migrate TestCoreListDeprecatedPlatformWithInstalledJson from test_core.py to core_test.go
1 parent 49f010a commit 6afbd7f

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

internal/integrationtest/core/core_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,40 @@ func TestCoreListSortedResults(t *testing.T) {
728728
require.True(t, strings.HasSuffix(platform, strings.TrimLeft(notSortedDeprecated, "[")))
729729

730730
}
731+
732+
func TestCoreListDeprecatedPlatformWithInstalledJson(t *testing.T) {
733+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
734+
defer env.CleanUp()
735+
736+
// Set up the server to serve our custom index file
737+
testIndex := paths.New("..", "testdata", "test_index.json")
738+
url := env.HTTPServeFile(8000, testIndex)
739+
740+
// update custom index
741+
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url.String())
742+
require.NoError(t, err)
743+
744+
// install some core for testing
745+
_, _, err = cli.Run("core", "install", "Package:x86", "--additional-urls="+url.String())
746+
require.NoError(t, err)
747+
748+
installedJsonFile := cli.DataDir().Join("packages", "Package", "hardware", "x86", "1.2.3", "installed.json")
749+
require.FileExists(t, installedJsonFile.String())
750+
lines, err := installedJsonFile.ReadFileAsLines()
751+
require.NoError(t, err)
752+
var json []byte
753+
for i, v := range lines {
754+
if i != 13 {
755+
json = append(json, []byte(v+"\n")...)
756+
}
757+
}
758+
err = installedJsonFile.WriteFile(json)
759+
require.NoError(t, err)
760+
761+
// test same behaviour with json output
762+
stdout, _, err := cli.Run("core", "list", "--additional-urls="+url.String(), "--format=json")
763+
require.NoError(t, err)
764+
765+
requirejson.Len(t, stdout, 1)
766+
requirejson.Query(t, stdout, ".[] | .deprecated", "true")
767+
}

test/test_core.py

-30
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)