@@ -21,6 +21,7 @@ import (
21
21
"io"
22
22
"testing"
23
23
24
+ "github.com/arduino/arduino-cli/internal/integrationtest"
24
25
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
25
26
"github.com/stretchr/testify/require"
26
27
)
@@ -41,57 +42,33 @@ func TestDaemonCoreUpdateIndex(t *testing.T) {
41
42
` "http://downloads.arduino.cc/package_inexistent_index.json"]` )
42
43
require .NoError (t , err )
43
44
45
+ analyzeUpdateIndexClient := func (cl commands.ArduinoCoreService_UpdateIndexClient ) map [string ]* commands.DownloadProgressEnd {
46
+ analyzer := integrationtest .NewDownloadProgressAnalyzer (t )
47
+ for {
48
+ msg , err := cl .Recv ()
49
+ if err == io .EOF {
50
+ break
51
+ }
52
+ require .NoError (t , err )
53
+ analyzer .Process (msg .GetDownloadProgress ())
54
+ }
55
+ return analyzer .Results
56
+ }
57
+
44
58
{
45
59
cl , err := grpcInst .UpdateIndex (context .Background (), true )
46
60
require .NoError (t , err )
47
- res , err := analyzeUpdateIndexStream (t , cl )
48
- require .NoError (t , err )
61
+ res := analyzeUpdateIndexClient (cl )
49
62
require .Len (t , res , 1 )
50
63
require .True (t , res ["https://downloads.arduino.cc/packages/package_index.tar.bz2" ].Success )
51
64
}
52
65
{
53
66
cl , err := grpcInst .UpdateIndex (context .Background (), false )
54
67
require .NoError (t , err )
55
- res , err := analyzeUpdateIndexStream (t , cl )
56
- require .Error (t , err )
68
+ res := analyzeUpdateIndexClient (cl )
57
69
require .Len (t , res , 3 )
58
70
require .True (t , res ["https://downloads.arduino.cc/packages/package_index.tar.bz2" ].Success )
59
71
require .True (t , res ["http://arduino.esp8266.com/stable/package_esp8266com_index.json" ].Success )
60
72
require .False (t , res ["http://downloads.arduino.cc/package_inexistent_index.json" ].Success )
61
73
}
62
74
}
63
-
64
- // analyzeUpdateIndexStream runs an update index checking if the sequence of DownloadProgress and
65
- // DownloadResult messages is correct. It returns a map reporting all the DownloadResults messages
66
- // received (it maps urls to DownloadResults).
67
- func analyzeUpdateIndexStream (t * testing.T , cl commands.ArduinoCoreService_UpdateIndexClient ) (map [string ]* commands.DownloadProgressEnd , error ) {
68
- ongoingDownload := ""
69
- results := map [string ]* commands.DownloadProgressEnd {}
70
- for {
71
- msg , err := cl .Recv ()
72
- if err == io .EOF {
73
- return results , nil
74
- }
75
- if err != nil {
76
- return results , err
77
- }
78
- require .NoError (t , err )
79
- fmt .Printf ("UPDATE> %+v\n " , msg )
80
- if progress := msg .GetDownloadProgress (); progress != nil {
81
- if start := progress .GetStart (); start != nil {
82
- require .Empty (t , ongoingDownload , "DownloadProgressStart: started a download without 'completing' the previous one" )
83
- ongoingDownload = start .Url
84
- } else if update := progress .GetUpdate (); update != nil {
85
- require .NotEmpty (t , ongoingDownload , "DownloadProgressUpdate: received update, but the download is not yet started..." )
86
- } else if end := progress .GetEnd (); end != nil {
87
- require .NotEmpty (t , ongoingDownload , "DownloadProgress: received a 'completed' notification but never initiated a download" )
88
- results [ongoingDownload ] = end
89
- ongoingDownload = ""
90
- } else {
91
- require .FailNow (t , "DownloadProgress: received an empty DownloadProgress (without Start, Update or End)" )
92
- }
93
- } else {
94
- require .FailNow (t , "DownloadProgress: received an empty message (without a DownloadProgress)" )
95
- }
96
- }
97
- }
0 commit comments