Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e5a811

Browse files
author
Luca Bianconi
committedJan 18, 2023
test: rescan libraries before install
1 parent 98ee870 commit 6e5a811

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed
 

‎arduino/libraries/librariesmanager/librariesmanager.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,9 @@ func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *core
130130
})
131131
}
132132

133-
func (lm *LibrariesManager) ClearLibraries() {
134-
for k := range lm.Libraries {
135-
delete(lm.Libraries, k)
136-
}
137-
}
138-
139133
// RescanLibraries reload all installed libraries in the system.
140134
func (lm *LibrariesManager) RescanLibraries() []*status.Status {
141-
lm.ClearLibraries()
135+
lm.clearLibraries()
142136
statuses := []*status.Status{}
143137
for _, dir := range lm.LibrariesDir {
144138
if errs := lm.LoadLibrariesFromDir(dir); len(errs) > 0 {
@@ -224,3 +218,9 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in
224218
}
225219
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
226220
}
221+
222+
func (lm *LibrariesManager) clearLibraries() {
223+
for k := range lm.Libraries {
224+
delete(lm.Libraries, k)
225+
}
226+
}

‎arduino/libraries/librariesmanager/librariesmanager_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 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.
115
package librariesmanager
216

317
import (

‎internal/integrationtest/daemon/daemon_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,36 @@ func TestDaemonBundleLibInstall(t *testing.T) {
382382
}
383383
}
384384
}
385+
386+
func TestDaemonLibrariesRescanOnInstall(t *testing.T) {
387+
/*
388+
Ensures that the libraries are rescanned prior to installing a new one,
389+
to avoid clashes with libraries installed after the daemon initialization.
390+
To perform the check:
391+
- the daemon is run and a gprc instance initialized
392+
- a library is installed through the cli
393+
- an attempt to install a new version of the library is done
394+
with the gprc instance
395+
The last attempt is expected to not raise an error
396+
*/
397+
env, cli := createEnvForDaemon(t)
398+
defer env.CleanUp()
399+
400+
grpcInst := cli.Create()
401+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
402+
fmt.Printf("INIT> %v\n", ir.GetMessage())
403+
}))
404+
cli.Run("lib", "install", "SD@1.2.3")
405+
406+
instCl, err := grpcInst.LibraryInstall(context.Background(), "SD", "1.2.4", false, false, true)
407+
408+
require.NoError(t, err)
409+
for {
410+
_, err := instCl.Recv()
411+
if err == io.EOF {
412+
break
413+
}
414+
require.NoError(t, err)
415+
}
416+
417+
}

0 commit comments

Comments
 (0)
Please sign in to comment.