|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-cli. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package upgrade_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "strings" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/arduino/arduino-cli/internal/integrationtest" |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | +) |
| 25 | + |
| 26 | +func TestUpgrade(t *testing.T) { |
| 27 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 28 | + defer env.CleanUp() |
| 29 | + |
| 30 | + // Updates index for cores and libraries |
| 31 | + _, _, err := cli.Run("core", "update-idex") |
| 32 | + require.NoError(t, err) |
| 33 | + _, _, err = cli.Run("lib", "update-idex") |
| 34 | + require.NoError(t, err) |
| 35 | + |
| 36 | + // Installs an outdated core and library |
| 37 | + _, _, err = cli. Run( "core", "install", "arduino:[email protected]") |
| 38 | + require.NoError(t, err) |
| 39 | + _, _, err = cli. Run( "lib", "install", "[email protected]") |
| 40 | + require.NoError(t, err) |
| 41 | + |
| 42 | + // Installs an outdated core and library |
| 43 | + _, _, err = cli.Run("core", "install", "arduino:samd") |
| 44 | + require.NoError(t, err) |
| 45 | + _, _, err = cli.Run("lib", "install", "ArduinoJson") |
| 46 | + require.NoError(t, err) |
| 47 | + |
| 48 | + // Verifies outdated core and libraries are shown |
| 49 | + stdout, _, err := cli.Run("outdated") |
| 50 | + require.NoError(t, err) |
| 51 | + lines := strings.Split(string(stdout), "\n") |
| 52 | + require.Contains(t, lines[1], "Arduino AVR Boards") |
| 53 | + require.Contains(t, lines[4], "USBHost") |
| 54 | + |
| 55 | + _, _, err = cli.Run("upgrade") |
| 56 | + require.NoError(t, err) |
| 57 | + |
| 58 | + // Verifies cores and libraries have been updated |
| 59 | + stdout, _, err = cli.Run("outdated") |
| 60 | + require.NoError(t, err) |
| 61 | + require.Equal(t, string(stdout), "\n") |
| 62 | +} |
| 63 | + |
| 64 | +func TestUpgradeUsingLibraryWithInvalidVersion(t *testing.T) { |
| 65 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 66 | + defer env.CleanUp() |
| 67 | + |
| 68 | + _, _, err := cli.Run("update") |
| 69 | + require.NoError(t, err) |
| 70 | + |
| 71 | + // Install latest version of a library |
| 72 | + _, _, err = cli.Run("lib", "install", "WiFi101") |
| 73 | + require.NoError(t, err) |
| 74 | + |
| 75 | + // Verifies library is not shown |
| 76 | + stdout, _, err := cli.Run("outdated") |
| 77 | + require.NoError(t, err) |
| 78 | + require.NotContains(t, string(stdout), "WiFi101") |
| 79 | + |
| 80 | + // Changes the version of the currently installed library so that it's invalid |
| 81 | + libPropPath := cli.SketchbookDir().Join("libraries", "WiFi101", "library.properties") |
| 82 | + err = libPropPath.WriteFile([]byte("name=WiFi101\nversion=1.0001")) |
| 83 | + require.NoError(t, err) |
| 84 | + |
| 85 | + // Verifies library gets upgraded |
| 86 | + stdout, _, err = cli.Run("upgrade") |
| 87 | + require.NoError(t, err) |
| 88 | + require.Contains(t, string(stdout), "WiFi101") |
| 89 | +} |
| 90 | + |
| 91 | +func TestUpgradeUnusedCoreToolsAreRemoved(t *testing.T) { |
| 92 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 93 | + defer env.CleanUp() |
| 94 | + |
| 95 | + _, _, err := cli.Run("update") |
| 96 | + require.NoError(t, err) |
| 97 | + |
| 98 | + // Installs a core |
| 99 | + _, _, err = cli. Run( "core", "install", "arduino:[email protected]") |
| 100 | + require.NoError(t, err) |
| 101 | + |
| 102 | + // Verifies expected tool is installed |
| 103 | + toolPath := cli.DataDir().Join("packages", "arduino", "tools", "avr-gcc", "7.3.0-atmel3.6.1-arduino5") |
| 104 | + require.DirExists(t, toolPath.String()) |
| 105 | + |
| 106 | + // Upgrades everything |
| 107 | + _, _, err = cli.Run("upgrade") |
| 108 | + require.NoError(t, err) |
| 109 | + |
| 110 | + // Verifies tool is uninstalled since it's not used by newer core version |
| 111 | + require.NoDirExists(t, toolPath.String()) |
| 112 | +} |
0 commit comments