Skip to content

Commit 6b5d96c

Browse files
committed
Fixed wrong usage of DownloadProgress
1 parent 9a43ead commit 6b5d96c

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

commands/instances.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
503503

504504
failed := false
505505
for _, u := range urls {
506-
downloadCB(rpc.NewDownloadProgressStart(u, tr("Downloading index: %s", u)))
507506
URL, err := utils.URLParse(u)
508507
if err != nil {
509508
logrus.Warnf("unable to parse additional URL: %s", u)
510509
msg := fmt.Sprintf("%s: %v", tr("Unable to parse URL"), err)
510+
downloadCB(rpc.NewDownloadProgressStart(u, tr("Downloading index: %s", u)))
511511
downloadCB(rpc.NewDownloadProgressEnd(false, msg))
512512
failed = true
513513
continue
@@ -516,6 +516,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
516516
logrus.WithField("url", URL).Print("Updating index")
517517

518518
if URL.Scheme == "file" {
519+
downloadCB(rpc.NewDownloadProgressStart(u, tr("Downloading index: %s", u)))
519520
path := paths.New(URL.Path)
520521
if _, err := packageindex.LoadIndexNoSign(path); err != nil {
521522
msg := fmt.Sprintf("%s: %v", tr("Invalid package index in %s", path), err)
@@ -533,10 +534,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
533534
indexResource.SignatureURL.Path += ".sig"
534535
}
535536
if err := indexResource.Download(indexpath, downloadCB); err != nil {
536-
downloadCB(rpc.NewDownloadProgressEnd(false, err.Error()))
537537
failed = true
538-
} else {
539-
downloadCB(rpc.NewDownloadProgressEnd(true, ""))
540538
}
541539
continue
542540
}

internal/integrationtest/daemon/daemon_core_test.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"io"
2222
"testing"
2323

24-
"github.com/arduino/arduino-cli/internal/integrationtest"
2524
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2625
"github.com/stretchr/testify/require"
2726
)
@@ -42,30 +41,35 @@ func TestDaemonCoreUpdateIndex(t *testing.T) {
4241
` "http://downloads.arduino.cc/package_inexistent_index.json"]`)
4342
require.NoError(t, err)
4443

45-
analyzeUpdateIndexClient := func(cl commands.ArduinoCoreService_UpdateIndexClient) map[string]*commands.DownloadProgressEnd {
46-
analyzer := integrationtest.NewDownloadProgressAnalyzer(t)
44+
analyzeUpdateIndexClient := func(cl commands.ArduinoCoreService_UpdateIndexClient) (error, map[string]*commands.DownloadProgressEnd) {
45+
analyzer := NewDownloadProgressAnalyzer(t)
4746
for {
4847
msg, err := cl.Recv()
48+
// fmt.Println("DOWNLOAD>", msg)
4949
if err == io.EOF {
50-
break
50+
return nil, analyzer.Results
51+
}
52+
if err != nil {
53+
return err, analyzer.Results
5154
}
5255
require.NoError(t, err)
5356
analyzer.Process(msg.GetDownloadProgress())
5457
}
55-
return analyzer.Results
5658
}
5759

5860
{
5961
cl, err := grpcInst.UpdateIndex(context.Background(), true)
6062
require.NoError(t, err)
61-
res := analyzeUpdateIndexClient(cl)
63+
err, res := analyzeUpdateIndexClient(cl)
64+
require.NoError(t, err)
6265
require.Len(t, res, 1)
6366
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Success)
6467
}
6568
{
6669
cl, err := grpcInst.UpdateIndex(context.Background(), false)
6770
require.NoError(t, err)
68-
res := analyzeUpdateIndexClient(cl)
71+
err, res := analyzeUpdateIndexClient(cl)
72+
require.Error(t, err)
6973
require.Len(t, res, 3)
7074
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Success)
7175
require.True(t, res["http://arduino.esp8266.com/stable/package_esp8266com_index.json"].Success)

internal/integrationtest/download_progress.go renamed to internal/integrationtest/daemon/download_progress_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package integrationtest
16+
package daemon_test
1717

1818
import (
1919
"testing"

0 commit comments

Comments
 (0)