Skip to content

[breaking] Fix behaviour of lib commands when a library is installed multiple times #1878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 21, 2022
Merged
24 changes: 24 additions & 0 deletions internal/integrationtest/lib/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,27 @@ func TestLibInstallMultipleSameLibrary(t *testing.T) {
require.NoError(t, err)
requirejson.Len(t, jsonOut, 1, "A duplicate library install has been detected")
}

func TestDuplicateLibInstallDetection(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
cliEnv := cli.GetDefaultEnv()
cliEnv["ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL"] = "true"

// Make a double install in the sketchbook/user directory
_, _, err := cli.Run("lib", "install", "[email protected]")
require.NoError(t, err)
otaLibPath := cli.SketchbookDir().Join("libraries", "ArduinoOTA")
err = otaLibPath.CopyDirTo(otaLibPath.Parent().Join("CopyOfArduinoOTA"))
require.NoError(t, err)
jsonOut, _, err := cli.Run("lib", "list", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, jsonOut, 2, "Duplicate library install is not detected by the CLI")

_, _, err = cli.Run("lib", "install", "ArduinoOTA")
require.Error(t, err)
_, _, err = cli.Run("lib", "upgrade", "ArduinoOTA")
require.Error(t, err)
_, _, err = cli.Run("lib", "uninstall", "ArduinoOTA")
require.Error(t, err)
}