|
| 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 license@arduino.cc. |
| 15 | + |
| 16 | +package lib_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/arduino/arduino-cli/internal/integrationtest" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + "go.bug.st/testifyjson/requirejson" |
| 24 | +) |
| 25 | + |
| 26 | +func TestLibUpgradeCommand(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-index") |
| 32 | + require.NoError(t, err) |
| 33 | + _, _, err = cli.Run("lib", "update-index") |
| 34 | + require.NoError(t, err) |
| 35 | + |
| 36 | + // Install core (this will help to check interaction with platform bundled libraries) |
| 37 | + _, _, err = cli.Run("core", "install", "arduino:avr@1.6.3") |
| 38 | + require.NoError(t, err) |
| 39 | + |
| 40 | + // Test upgrade of not-installed library |
| 41 | + _, stdErr, err := cli.Run("lib", "upgrade", "Servo") |
| 42 | + require.Error(t, err) |
| 43 | + require.Contains(t, string(stdErr), "Library 'Servo' not found") |
| 44 | + |
| 45 | + // Test upgrade of installed library |
| 46 | + _, _, err = cli.Run("lib", "install", "Servo@1.1.6") |
| 47 | + require.NoError(t, err) |
| 48 | + stdOut, _, err := cli.Run("lib", "list", "--format", "json") |
| 49 | + require.NoError(t, err) |
| 50 | + requirejson.Contains(t, stdOut, `[ { "library":{ "name":"Servo", "version": "1.1.6" } } ]`) |
| 51 | + |
| 52 | + _, _, err = cli.Run("lib", "upgrade", "Servo") |
| 53 | + require.NoError(t, err) |
| 54 | + stdOut, _, err = cli.Run("lib", "list", "--format", "json") |
| 55 | + require.NoError(t, err) |
| 56 | + jsonOut := requirejson.Parse(t, stdOut) |
| 57 | + jsonOut.MustNotContain(`[ { "library":{ "name":"Servo", "version": "1.1.6" } } ]`) |
| 58 | + servoVersion := jsonOut.Query(`.[].library | select(.name=="Servo") | .version`).String() |
| 59 | + |
| 60 | + // Upgrade of already up-to-date library |
| 61 | + _, _, err = cli.Run("lib", "upgrade", "Servo") |
| 62 | + require.NoError(t, err) |
| 63 | + stdOut, _, err = cli.Run("lib", "list", "--format", "json") |
| 64 | + require.NoError(t, err) |
| 65 | + requirejson.Query(t, stdOut, `.[].library | select(.name=="Servo") | .version`, servoVersion) |
| 66 | +} |
0 commit comments