Commit 917b9e25 authored by Cristian Maglie's avatar Cristian Maglie

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.
parent 8c6228ab
......@@ -426,6 +426,42 @@ func TestCompileCommands(t *testing.T) {
require.True(t, paths.New("anothertest", "test2.hex").Exist())
}
func TestInvalidCoreURL(t *testing.T) {
defer makeTempDataDir(t)()
defer makeTempSketchbookDir(t)()
tmp, err := paths.MkTempDir("", "")
require.NoError(t, err, "making temporary dir")
defer tmp.RemoveAll()
configFile := tmp.Join("cli-config.yml")
configFile.WriteFile([]byte(`
board_manager:
additional_urls:
- http://www.example.com/package_example_index.json
`))
require.NoError(t, currDataDir.MkdirAll())
err = currDataDir.Join("package_index.json").WriteFile([]byte(`{ "packages": [] }`))
require.NoError(t, err, "Writing empty json index file")
err = currDataDir.Join("package_example_index.json").WriteFile([]byte(`{ "packages": [] }`))
require.NoError(t, err, "Writing empty json index file")
// Empty cores list
exitCode, d := executeWithArgs(t, "--config-file", configFile.String(), "core", "list")
require.Zero(t, exitCode, "exit code")
require.Empty(t, strings.TrimSpace(string(d)))
// Empty cores list
exitCode, _ = executeWithArgs(t, "--config-file", configFile.String(), "core", "update-index")
require.NotZero(t, exitCode, "exit code")
// Empty cores list
exitCode, d = executeWithArgs(t, "--config-file", configFile.String(), "core", "list")
require.Zero(t, exitCode, "exit code")
require.Empty(t, strings.TrimSpace(string(d)))
}
func TestCoreCommands(t *testing.T) {
defer makeTempDataDir(t)()
defer makeTempSketchbookDir(t)()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment