@@ -17,10 +17,13 @@ package lib_test
17
17
18
18
import (
19
19
"encoding/json"
20
+ "io"
21
+ "net/http"
20
22
"strings"
21
23
"testing"
22
24
23
25
"github.com/arduino/arduino-cli/internal/integrationtest"
26
+ "github.com/arduino/go-paths-helper"
24
27
"github.com/stretchr/testify/require"
25
28
"go.bug.st/testifyjson/requirejson"
26
29
)
@@ -164,6 +167,42 @@ func TestDuplicateLibInstallFromGitDetection(t *testing.T) {
164
167
requirejson .Parse (t , jsonOut ).
165
168
Query (`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]` ).
166
169
LengthMustEqualTo (1 , "Found multiple installations of Arduino SigFox for MKRFox1200'" )
170
+
171
+ // Try to make a double install by upgrade
172
+ _ , _ , err = cli .Run ("lib" , "upgrade" )
173
+ require .NoError (t , err )
174
+
175
+ // Check if double install happened
176
+ jsonOut , _ , err = cli .Run ("lib" , "list" , "--format" , "json" )
177
+ require .NoError (t , err )
178
+ requirejson .Parse (t , jsonOut ).
179
+ Query (`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]` ).
180
+ LengthMustEqualTo (1 , "Found multiple installations of Arduino SigFox for MKRFox1200'" )
181
+
182
+ // Try to make a double install by zip-installing
183
+ tmp , err := paths .MkTempDir ("" , "" )
184
+ require .NoError (t , err )
185
+ defer tmp .RemoveAll ()
186
+ tmpZip := tmp .Join ("SigFox.zip" )
187
+ defer tmpZip .Remove ()
188
+
189
+ f , err := tmpZip .Create ()
190
+ require .NoError (t , err )
191
+ resp , err := http .Get ("https://github.com/arduino-libraries/SigFox/archive/refs/tags/1.0.3.zip" )
192
+ require .NoError (t , err )
193
+ _ , err = io .Copy (f , resp .Body )
194
+ require .NoError (t , err )
195
+ require .NoError (t , f .Close ())
196
+
197
+ _ , _ , err = cli .RunWithCustomEnv (cliEnv , "lib" , "install" , "--zip-path" , tmpZip .String ())
198
+ require .NoError (t , err )
199
+
200
+ // Check if double install happened
201
+ jsonOut , _ , err = cli .Run ("lib" , "list" , "--format" , "json" )
202
+ require .NoError (t , err )
203
+ requirejson .Parse (t , jsonOut ).
204
+ Query (`[.[].library.name | select(. == "Arduino SigFox for MKRFox1200")]` ).
205
+ LengthMustEqualTo (1 , "Found multiple installations of Arduino SigFox for MKRFox1200'" )
167
206
}
168
207
169
208
func TestLibDepsOutput (t * testing.T ) {
0 commit comments