Skip to content

Commit f7618d6

Browse files
Migrate TestCoreListWithInstalledJson from test_core.py to core_test.go
1 parent 4d503be commit f7618d6

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

internal/integrationtest/core/core_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,51 @@ func TestCoreInstallRemovesUnusedTools(t *testing.T) {
534534
// Verifies tool is uninstalled since it's not used by newer core version
535535
require.NoDirExists(t, toolPath.String())
536536
}
537+
538+
func TestCoreListWithInstalledJson(t *testing.T) {
539+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
540+
defer env.CleanUp()
541+
542+
_, _, err := cli.Run("update")
543+
require.NoError(t, err)
544+
545+
// Install core
546+
url := "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
547+
_, _, err = cli.Run("core", "update-index", "--additional-urls="+url)
548+
require.NoError(t, err)
549+
_, _, err = cli.Run("core", "install", "adafruit:avr@1.4.13", "--additional-urls="+url)
550+
require.NoError(t, err)
551+
552+
// Verifies installed core is correctly found and name is set
553+
stdout, _, err := cli.Run("core", "list", "--format", "json")
554+
require.NoError(t, err)
555+
requirejson.Len(t, stdout, 1)
556+
requirejson.Contains(t, stdout, `[
557+
{
558+
"id": "adafruit:avr",
559+
"name": "Adafruit AVR Boards"
560+
}
561+
]`)
562+
563+
// Deletes installed.json file, this file stores information about the core,
564+
// that is used mostly when removing package indexes and their cores are still installed;
565+
// this way we don't lose much information about it.
566+
// It might happen that the user has old cores installed before the addition of
567+
// the installed.json file so we need to handle those cases.
568+
installedJson := cli.DataDir().Join("packages", "adafruit", "hardware", "avr", "1.4.13", "installed.json")
569+
require.NoError(t, installedJson.Remove())
570+
571+
// Verifies installed core is still found and name is set
572+
stdout, _, err = cli.Run("core", "list", "--format", "json")
573+
require.NoError(t, err)
574+
requirejson.Len(t, stdout, 1)
575+
// Name for this core changes since if there's installed.json file we read it from
576+
// platform.txt, turns out that this core has different names used in different files
577+
// thus the change.
578+
requirejson.Contains(t, stdout, `[
579+
{
580+
"id": "adafruit:avr",
581+
"name": "Adafruit Boards"
582+
}
583+
]`)
584+
}

test/test_core.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -68,44 +68,6 @@ def ordered(obj):
6868
assert ordered(installed_json) == ordered(expected_installed_json)
6969

7070

71-
def test_core_list_with_installed_json(run_command, data_dir):
72-
assert run_command(["update"])
73-
74-
# Install core
75-
url = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
76-
assert run_command(["core", "update-index", f"--additional-urls={url}"])
77-
assert run_command(["core", "install", "adafruit:avr@1.4.13", f"--additional-urls={url}"])
78-
79-
# Verifies installed core is correctly found and name is set
80-
res = run_command(["core", "list", "--format", "json"])
81-
assert res.ok
82-
cores = json.loads(res.stdout)
83-
mapped = {core["id"]: core for core in cores}
84-
assert len(mapped) == 1
85-
assert "adafruit:avr" in mapped
86-
assert mapped["adafruit:avr"]["name"] == "Adafruit AVR Boards"
87-
88-
# Deletes installed.json file, this file stores information about the core,
89-
# that is used mostly when removing package indexes and their cores are still installed;
90-
# this way we don't lose much information about it.
91-
# It might happen that the user has old cores installed before the addition of
92-
# the installed.json file so we need to handle those cases.
93-
installed_json = Path(data_dir, "packages", "adafruit", "hardware", "avr", "1.4.13", "installed.json")
94-
installed_json.unlink()
95-
96-
# Verifies installed core is still found and name is set
97-
res = run_command(["core", "list", "--format", "json"])
98-
assert res.ok
99-
cores = json.loads(res.stdout)
100-
mapped = {core["id"]: core for core in cores}
101-
assert len(mapped) == 1
102-
assert "adafruit:avr" in mapped
103-
# Name for this core changes since if there's installed.json file we read it from
104-
# platform.txt, turns out that this core has different names used in different files
105-
# thus the change.
106-
assert mapped["adafruit:avr"]["name"] == "Adafruit Boards"
107-
108-
10971
def test_core_search_update_index_delay(run_command, data_dir):
11072
assert run_command(["update"])
11173

0 commit comments

Comments
 (0)