Skip to content

Commit c5b180c

Browse files
Migrate TestSetSliceWithMultipleArguments from test_config.py to config_test.go
1 parent 521c254 commit c5b180c

File tree

2 files changed

+58
-41
lines changed

2 files changed

+58
-41
lines changed

internal/integrationtest/config/config_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,61 @@ func TestSetSliceWithSingleArgument(t *testing.T) {
526526
require.NoError(t, err)
527527
requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[\"https://example.com/yet_another_package_example_index.json\"]")
528528
}
529+
530+
func TestSetSliceWithMultipleArguments(t *testing.T) {
531+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
532+
defer env.CleanUp()
533+
534+
// Create a config file
535+
_, _, err := cli.Run("config", "init", "--dest-dir", ".")
536+
require.NoError(t, err)
537+
538+
// Verifies default state
539+
stdout, _, err := cli.Run("config", "dump", "--format", "json")
540+
require.NoError(t, err)
541+
requirejson.Query(t, stdout, ".board_manager | .additional_urls", "[]")
542+
543+
// Set some URLs in the list
544+
urls := [2]string{
545+
"https://example.com/first_package_index.json",
546+
"https://example.com/second_package_index.json",
547+
}
548+
_, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1])
549+
require.NoError(t, err)
550+
551+
// Verifies value is changed
552+
stdout, _, err = cli.Run("config", "dump", "--format", "json")
553+
require.NoError(t, err)
554+
requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2")
555+
requirejson.Contains(t, stdout, `
556+
{
557+
"board_manager": {
558+
"additional_urls": [
559+
"https://example.com/first_package_index.json",
560+
"https://example.com/second_package_index.json"
561+
]
562+
}
563+
}`)
564+
565+
// Set some URLs in the list
566+
urls = [2]string{
567+
"https://example.com/third_package_index.json",
568+
"https://example.com/fourth_package_index.json",
569+
}
570+
_, _, err = cli.Run("config", "set", "board_manager.additional_urls", urls[0], urls[1])
571+
require.NoError(t, err)
572+
573+
// Verifies previous value is overwritten
574+
stdout, _, err = cli.Run("config", "dump", "--format", "json")
575+
require.NoError(t, err)
576+
requirejson.Query(t, stdout, ".board_manager | .additional_urls | length", "2")
577+
requirejson.Contains(t, stdout, `
578+
{
579+
"board_manager": {
580+
"additional_urls": [
581+
"https://example.com/third_package_index.json",
582+
"https://example.com/fourth_package_index.json"
583+
]
584+
}
585+
}`)
586+
}

test/test_config.py

-41
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,6 @@
1717
import yaml
1818

1919

20-
def test_set_slice_with_multiple_arguments(run_command):
21-
# Create a config file
22-
assert run_command(["config", "init", "--dest-dir", "."])
23-
24-
# Verifies default state
25-
result = run_command(["config", "dump", "--format", "json"])
26-
assert result.ok
27-
settings_json = json.loads(result.stdout)
28-
assert [] == settings_json["board_manager"]["additional_urls"]
29-
30-
# Set some URLs in the list
31-
urls = [
32-
"https://example.com/first_package_index.json",
33-
"https://example.com/second_package_index.json",
34-
]
35-
assert run_command(["config", "set", "board_manager.additional_urls"] + urls)
36-
37-
# Verifies value is changed
38-
result = run_command(["config", "dump", "--format", "json"])
39-
assert result.ok
40-
settings_json = json.loads(result.stdout)
41-
assert 2 == len(settings_json["board_manager"]["additional_urls"])
42-
assert urls[0] in settings_json["board_manager"]["additional_urls"]
43-
assert urls[1] in settings_json["board_manager"]["additional_urls"]
44-
45-
# Sets another set of URL
46-
urls = [
47-
"https://example.com/third_package_index.json",
48-
"https://example.com/fourth_package_index.json",
49-
]
50-
assert run_command(["config", "set", "board_manager.additional_urls"] + urls)
51-
52-
# Verifies previous value is overwritten
53-
result = run_command(["config", "dump", "--format", "json"])
54-
assert result.ok
55-
settings_json = json.loads(result.stdout)
56-
assert 2 == len(settings_json["board_manager"]["additional_urls"])
57-
assert urls[0] in settings_json["board_manager"]["additional_urls"]
58-
assert urls[1] in settings_json["board_manager"]["additional_urls"]
59-
60-
6120
def test_set_string_with_single_argument(run_command):
6221
# Create a config file
6322
assert run_command(["config", "init", "--dest-dir", "."])

0 commit comments

Comments
 (0)