Skip to content

Commit 120b852

Browse files
[skip-changelog] Migrate tests from test_update.py to update_test.go (#1933)
* Migrate TestUpdate from test_update.py to update_test.go * Migrate TestUpdateShowingOutdated from test_update.py to update_test.go * Migrate TestUpdateWithUrlNotFound from test_update.py to update_test.go * Migrate TestUpdateWithUrlInternalServerError from test_update.py to update_test.go * Migrate TestUpdateShowingOutdatedUsingLibraryWithInvalidVersion to update_test.go and delete test_update.py
1 parent 960c210 commit 120b852

File tree

2 files changed

+128
-97
lines changed

2 files changed

+128
-97
lines changed

Diff for: internal/integrationtest/update/update_test.go

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 update_test
17+
18+
import (
19+
"strings"
20+
"testing"
21+
22+
"github.com/arduino/arduino-cli/internal/integrationtest"
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/stretchr/testify/require"
25+
)
26+
27+
func TestUpdate(t *testing.T) {
28+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
29+
defer env.CleanUp()
30+
31+
stdout, _, err := cli.Run("update")
32+
require.NoError(t, err)
33+
require.Contains(t, string(stdout), "Downloading index: package_index.tar.bz2 downloaded")
34+
require.Contains(t, string(stdout), "Downloading index: library_index.tar.bz2 downloaded")
35+
}
36+
37+
func TestUpdateShowingOutdated(t *testing.T) {
38+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
39+
defer env.CleanUp()
40+
41+
// Updates index for cores and libraries
42+
_, _, err := cli.Run("core", "update-index")
43+
require.NoError(t, err)
44+
_, _, err = cli.Run("lib", "update-index")
45+
require.NoError(t, err)
46+
47+
// Installs an outdated core and library
48+
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
49+
require.NoError(t, err)
50+
_, _, err = cli.Run("lib", "install", "[email protected]")
51+
require.NoError(t, err)
52+
53+
// Installs latest version of a core and a library
54+
_, _, err = cli.Run("core", "install", "arduino:samd")
55+
require.NoError(t, err)
56+
_, _, err = cli.Run("lib", "install", "ArduinoJson")
57+
require.NoError(t, err)
58+
59+
// Verifies outdated cores and libraries are printed after updating indexes
60+
stdout, _, err := cli.Run("update", "--show-outdated")
61+
require.NoError(t, err)
62+
lines := strings.Split(string(stdout), "\n")
63+
for i := range lines {
64+
lines[i] = strings.TrimSpace(lines[i])
65+
}
66+
67+
require.Contains(t, lines[0], "Downloading index: package_index.tar.bz2 downloaded")
68+
require.Contains(t, lines[1], "Downloading index: library_index.tar.bz2 downloaded")
69+
require.True(t, strings.HasPrefix(lines[3], "Arduino AVR Boards"))
70+
require.True(t, strings.HasPrefix(lines[6], "USBHost"))
71+
}
72+
73+
func TestUpdateWithUrlNotFound(t *testing.T) {
74+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
75+
defer env.CleanUp()
76+
77+
_, _, err := cli.Run("update")
78+
require.NoError(t, err)
79+
80+
// Brings up a local server to fake a failure
81+
url := env.HTTPServeFileError(8000, paths.New("test_index.json"), 404)
82+
83+
stdout, _, err := cli.Run("update", "--additional-urls="+url.String())
84+
require.Error(t, err)
85+
require.Contains(t, string(stdout), "Downloading index: test_index.json Server responded with: 404 Not Found")
86+
}
87+
88+
func TestUpdateWithUrlInternalServerError(t *testing.T) {
89+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
90+
defer env.CleanUp()
91+
92+
_, _, err := cli.Run("update")
93+
require.NoError(t, err)
94+
95+
// Brings up a local server to fake a failure
96+
url := env.HTTPServeFileError(8000, paths.New("test_index.json"), 500)
97+
98+
stdout, _, err := cli.Run("update", "--additional-urls="+url.String())
99+
require.Error(t, err)
100+
require.Contains(t, string(stdout), "Downloading index: test_index.json Server responded with: 500 Internal Server Error")
101+
}
102+
103+
func TestUpdateShowingOutdatedUsingLibraryWithInvalidVersion(t *testing.T) {
104+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
105+
defer env.CleanUp()
106+
107+
_, _, err := cli.Run("update")
108+
require.NoError(t, err)
109+
110+
// Install latest version of a library
111+
_, _, err = cli.Run("lib", "install", "WiFi101")
112+
require.NoError(t, err)
113+
114+
// Verifies library doesn't get updated
115+
stdout, _, err := cli.Run("update", "--show-outdated")
116+
require.NoError(t, err)
117+
require.NotContains(t, string(stdout), "WiFi101")
118+
119+
// Changes the version of the currently installed library so that it's
120+
// invalid
121+
libPath := cli.SketchbookDir().Join("libraries", "WiFi101", "library.properties")
122+
require.NoError(t, libPath.WriteFile([]byte("name=WiFi101\nversion=1.0001")))
123+
124+
// Verifies library gets updated
125+
stdout, _, err = cli.Run("update", "--show-outdated")
126+
require.NoError(t, err)
127+
require.Contains(t, string(stdout), "WiFi101")
128+
}

Diff for: test/test_update.py

-97
This file was deleted.

0 commit comments

Comments
 (0)