Skip to content

Commit f77d895

Browse files
committed
Added tests for invalid 3rd-party URL
as explained in #81: It says all packages were downloaded: Updating index: package_index.json downloaded Updating index: package_esp8266com_index.json downloaded Updating index: package_lalala_index.json downloaded But when you run commands like arduino-cli core list or arduino-cli board listall it exits with an error: Error: loading json index file /Users/MY_USER_NAME/arduino-cli/data/package_lalala_index.json: invalid character '<' looking for beginning of value Failed to load http://google.com/package_lalala_index.json package index. Try updating all indexes with `arduino-cli core update-index`. It occurs, because package_lalala_index.json contains 404 HTML page.
1 parent af68590 commit f77d895

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: commands/commands_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,42 @@ func TestCompileCommands(t *testing.T) {
426426
require.True(t, paths.New("anothertest", "test2.hex").Exist())
427427
}
428428

429+
func TestInvalidCoreURL(t *testing.T) {
430+
defer makeTempDataDir(t)()
431+
defer makeTempSketchbookDir(t)()
432+
433+
tmp, err := paths.MkTempDir("", "")
434+
require.NoError(t, err, "making temporary dir")
435+
defer tmp.RemoveAll()
436+
437+
configFile := tmp.Join("cli-config.yml")
438+
configFile.WriteFile([]byte(`
439+
board_manager:
440+
additional_urls:
441+
- http://www.example.com/package_example_index.json
442+
`))
443+
444+
require.NoError(t, currDataDir.MkdirAll())
445+
err = currDataDir.Join("package_index.json").WriteFile([]byte(`{ "packages": [] }`))
446+
require.NoError(t, err, "Writing empty json index file")
447+
err = currDataDir.Join("package_example_index.json").WriteFile([]byte(`{ "packages": [] }`))
448+
require.NoError(t, err, "Writing empty json index file")
449+
450+
// Empty cores list
451+
exitCode, d := executeWithArgs(t, "--config-file", configFile.String(), "core", "list")
452+
require.Zero(t, exitCode, "exit code")
453+
require.Empty(t, strings.TrimSpace(string(d)))
454+
455+
// Empty cores list
456+
exitCode, _ = executeWithArgs(t, "--config-file", configFile.String(), "core", "update-index")
457+
require.NotZero(t, exitCode, "exit code")
458+
459+
// Empty cores list
460+
exitCode, d = executeWithArgs(t, "--config-file", configFile.String(), "core", "list")
461+
require.Zero(t, exitCode, "exit code")
462+
require.Empty(t, strings.TrimSpace(string(d)))
463+
}
464+
429465
func TestCoreCommands(t *testing.T) {
430466
defer makeTempDataDir(t)()
431467
defer makeTempSketchbookDir(t)()

0 commit comments

Comments
 (0)