@@ -12,12 +12,13 @@ import TestZip from '../testAssets/TestZip';
1212import { downloadAndInstallPackages } from '../../../src/packageManager/downloadAndInstallPackages' ;
1313import NetworkSettings from '../../../src/NetworkSettings' ;
1414import { EventStream } from '../../../src/EventStream' ;
15- import { DownloadStart , DownloadSizeObtained , DownloadProgress , DownloadSuccess , InstallationStart , PackageInstallStart } from '../../../src/omnisharp/loggingEvents' ;
15+ import { DownloadStart , DownloadSizeObtained , DownloadProgress , DownloadSuccess , InstallationStart , PackageInstallStart , IntegrityCheckFailure } from '../../../src/omnisharp/loggingEvents' ;
1616import MockHttpsServer from '../testAssets/MockHttpsServer' ;
1717import { createTestFile } from '../testAssets/TestFile' ;
1818import TestEventBus from '../testAssets/TestEventBus' ;
1919import { AbsolutePathPackage } from '../../../src/packageManager/AbsolutePathPackage' ;
2020import { AbsolutePath } from '../../../src/packageManager/AbsolutePath' ;
21+ import { DownloadValidator } from '../../../src/packageManager/isValidDownload' ;
2122
2223chai . use ( chaiAsPromised ) ;
2324let expect = chai . expect ;
@@ -31,6 +32,7 @@ suite(`${downloadAndInstallPackages.name}`, () => {
3132 let eventBus : TestEventBus ;
3233 let downloadablePackage : AbsolutePathPackage [ ] ;
3334 let notDownloadablePackage : AbsolutePathPackage [ ] ;
35+ let downloadValidator : DownloadValidator = ( ) => true ;
3436
3537 const packageDescription = "Test Package" ;
3638 const networkSettingsProvider = ( ) => new NetworkSettings ( undefined , false ) ;
@@ -45,7 +47,7 @@ suite(`${downloadAndInstallPackages.name}`, () => {
4547 {
4648 url : `${ server . baseUrl } /downloadablePackage` ,
4749 description : packageDescription ,
48- installPath : new AbsolutePath ( tmpDirPath )
50+ installPath : new AbsolutePath ( tmpDirPath ) ,
4951 } ] ;
5052
5153 notDownloadablePackage = < AbsolutePathPackage [ ] > [
@@ -66,21 +68,16 @@ suite(`${downloadAndInstallPackages.name}`, () => {
6668 } ) ;
6769
6870 suite ( "If the download and install succeeds" , ( ) => {
69- test ( "The expected files are installs at the specified path" , async ( ) => {
70- await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream ) ;
71+ test ( "The expected files are installed at the specified path" , async ( ) => {
72+ await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) ;
7173 for ( let elem of testZip . files ) {
7274 let filePath = path . join ( tmpDirPath , elem . path ) ;
7375 expect ( await util . fileExists ( filePath ) ) . to . be . true ;
7476 }
7577 } ) ;
7678
7779 test ( "install.Lock is present" , async ( ) => {
78- await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream ) ;
79- for ( let elem of testZip . files ) {
80- let filePath = path . join ( tmpDirPath , elem . path ) ;
81- expect ( await util . fileExists ( filePath ) ) . to . be . true ;
82- }
83-
80+ await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) ;
8481 expect ( await util . fileExists ( path . join ( tmpDirPath , "install.Lock" ) ) ) . to . be . true ;
8582 } ) ;
8683
@@ -94,20 +91,68 @@ suite(`${downloadAndInstallPackages.name}`, () => {
9491 new InstallationStart ( packageDescription )
9592 ] ;
9693
97- await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream ) ;
98- console . log ( eventBus . getEvents ( ) ) ;
94+ await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) ;
95+ expect ( eventBus . getEvents ( ) ) . to . be . deep . equal ( eventsSequence ) ;
96+ } ) ;
97+
98+ test ( "If the download validation fails for the first time and passed second time, the correct events are logged" , async ( ) => {
99+ let count = 1 ;
100+ let downloadValidator = ( ) => {
101+ if ( count > 1 ) {
102+ return true ; // fail the first time and then pass the subsequent times
103+ }
104+
105+ count ++ ;
106+ return false ;
107+ } ;
108+
109+ let eventsSequence = [
110+ new PackageInstallStart ( ) ,
111+ new DownloadStart ( packageDescription ) ,
112+ new DownloadSizeObtained ( testZip . size ) ,
113+ new DownloadProgress ( 100 , packageDescription ) ,
114+ new DownloadSuccess ( ' Done!' ) ,
115+ new IntegrityCheckFailure ( packageDescription , downloadablePackage [ 0 ] . url , true ) ,
116+ new DownloadStart ( packageDescription ) ,
117+ new DownloadSizeObtained ( testZip . size ) ,
118+ new DownloadProgress ( 100 , packageDescription ) ,
119+ new DownloadSuccess ( ' Done!' ) ,
120+ new InstallationStart ( packageDescription )
121+ ] ;
122+
123+ await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) ;
99124 expect ( eventBus . getEvents ( ) ) . to . be . deep . equal ( eventsSequence ) ;
100125 } ) ;
101126 } ) ;
102127
103128 suite ( "If the download and install fails" , ( ) => {
129+ test ( "If the download succeeds but the validation fails, events are logged" , async ( ) => {
130+ let downloadValidator = ( ) => false ;
131+ let eventsSequence = [
132+ new PackageInstallStart ( ) ,
133+ new DownloadStart ( packageDescription ) ,
134+ new DownloadSizeObtained ( testZip . size ) ,
135+ new DownloadProgress ( 100 , packageDescription ) ,
136+ new DownloadSuccess ( ' Done!' ) ,
137+ new IntegrityCheckFailure ( packageDescription , downloadablePackage [ 0 ] . url , true ) ,
138+ new DownloadStart ( packageDescription ) ,
139+ new DownloadSizeObtained ( testZip . size ) ,
140+ new DownloadProgress ( 100 , packageDescription ) ,
141+ new DownloadSuccess ( ' Done!' ) ,
142+ new IntegrityCheckFailure ( packageDescription , downloadablePackage [ 0 ] . url , false ) ,
143+ ] ;
144+
145+ await downloadAndInstallPackages ( downloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) ;
146+ expect ( eventBus . getEvents ( ) ) . to . be . deep . equal ( eventsSequence ) ;
147+ } ) ;
148+
104149 test ( "Throws an exception when the download fails" , async ( ) => {
105- await downloadAndInstallPackages ( notDownloadablePackage , networkSettingsProvider , eventStream ) . should . be . rejected ;
150+ await downloadAndInstallPackages ( notDownloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) . should . be . rejected ;
106151 } ) ;
107152
108153 test ( "install.Lock is not present when the download fails" , async ( ) => {
109154 try {
110- await downloadAndInstallPackages ( notDownloadablePackage , networkSettingsProvider , eventStream ) ;
155+ await downloadAndInstallPackages ( notDownloadablePackage , networkSettingsProvider , eventStream , downloadValidator ) ;
111156 }
112157 catch ( error ) {
113158 expect ( await util . fileExists ( path . join ( tmpDirPath , "install.Lock" ) ) ) . to . be . false ;
0 commit comments