@@ -41,59 +41,38 @@ func TestDaemonCoreUpdateIndex(t *testing.T) {
41
41
` "http://downloads.arduino.cc/package_inexistent_index.json"]` )
42
42
require .NoError (t , err )
43
43
44
+ analyzeUpdateIndexClient := func (cl commands.ArduinoCoreService_UpdateIndexClient ) (error , map [string ]* commands.DownloadProgressEnd ) {
45
+ analyzer := NewDownloadProgressAnalyzer (t )
46
+ for {
47
+ msg , err := cl .Recv ()
48
+ // fmt.Println("DOWNLOAD>", msg)
49
+ if err == io .EOF {
50
+ return nil , analyzer .Results
51
+ }
52
+ if err != nil {
53
+ return err , analyzer .Results
54
+ }
55
+ require .NoError (t , err )
56
+ analyzer .Process (msg .GetDownloadProgress ())
57
+ }
58
+ }
59
+
44
60
{
45
61
cl , err := grpcInst .UpdateIndex (context .Background (), true )
46
62
require .NoError (t , err )
47
- res , err := analyzeUpdateIndexStream ( t , cl )
63
+ err , res := analyzeUpdateIndexClient ( cl )
48
64
require .NoError (t , err )
49
65
require .Len (t , res , 1 )
50
- require .True (t , res ["https://downloads.arduino.cc/packages/package_index.tar.bz2" ].Successful )
66
+ require .True (t , res ["https://downloads.arduino.cc/packages/package_index.tar.bz2" ].Success )
51
67
}
52
68
{
53
69
cl , err := grpcInst .UpdateIndex (context .Background (), false )
54
70
require .NoError (t , err )
55
- res , err := analyzeUpdateIndexStream ( t , cl )
71
+ err , res := analyzeUpdateIndexClient ( cl )
56
72
require .Error (t , err )
57
73
require .Len (t , res , 3 )
58
- require .True (t , res ["https://downloads.arduino.cc/packages/package_index.tar.bz2" ].Successful )
59
- require .True (t , res ["http://arduino.esp8266.com/stable/package_esp8266com_index.json" ].Successful )
60
- require .False (t , res ["http://downloads.arduino.cc/package_inexistent_index.json" ].Successful )
61
- }
62
- }
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.DownloadResult , error ) {
68
- ongoingDownload := ""
69
- results := map [string ]* commands.DownloadResult {}
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 progress .Url != "" && progress .Url != ongoingDownload {
82
- require .Empty (t , ongoingDownload , "DownloadProgress: started a download without 'completing' the previous one" )
83
- ongoingDownload = progress .Url
84
- }
85
- if progress .Completed {
86
- require .NotEmpty (t , ongoingDownload , "DownloadProgress: received a 'completed' notification but never initiated a download" )
87
- ongoingDownload = ""
88
- }
89
- if progress .Downloaded > 0 {
90
- require .NotEmpty (t , ongoingDownload , "DownloadProgress: received a download update but never initiated a download" )
91
- }
92
- } else if result := msg .GetDownloadResult (); result != nil {
93
- require .Empty (t , ongoingDownload , "DownloadResult: got a download result without completing the current download first" )
94
- results [result .Url ] = result
95
- } else {
96
- require .FailNow (t , "DownloadProgress: received an empty message (without a Progress or a Result)" )
97
- }
74
+ require .True (t , res ["https://downloads.arduino.cc/packages/package_index.tar.bz2" ].Success )
75
+ require .True (t , res ["http://arduino.esp8266.com/stable/package_esp8266com_index.json" ].Success )
76
+ require .False (t , res ["http://downloads.arduino.cc/package_inexistent_index.json" ].Success )
98
77
}
99
78
}
0 commit comments