@@ -5,6 +5,7 @@ import { ArmDeployment } from "../models/armTemplates";
55import { DeploymentConfig } from "../models/serverless" ;
66import { MockFactory } from "../test/mockFactory" ;
77import { RollbackService } from "./rollbackService" ;
8+ import fs from "fs" ;
89
910jest . mock ( "./azureBlobStorageService" ) ;
1011import { AzureBlobStorageService } from "./azureBlobStorageService" ;
@@ -31,9 +32,10 @@ describe("Rollback Service", () => {
3132 const containerName = "deployment-artifacts" ;
3233 const artifactName = MockFactory . createTestDeployment ( ) . name . replace (
3334 configConstants . naming . suffix . deployment , configConstants . naming . suffix . artifact ) + ".zip" ;
34- const artifactPath = `.serverless ${ path . sep } ${ artifactName } `
35+ const artifactPath = path . join ( ".serverless" , artifactName ) ;
3536 const armDeployment : ArmDeployment = { template, parameters } ;
3637 const deploymentString = "deployments" ;
38+ let unlinkSpy : jest . SpyInstance ;
3739
3840 function createOptions ( timestamp ?: string ) : Serverless . Options {
3941 return {
@@ -64,10 +66,12 @@ describe("Rollback Service", () => {
6466 ResourceService . prototype . listDeployments = jest . fn ( ( ) => Promise . resolve ( deploymentString ) )
6567 AzureBlobStorageService . prototype . generateBlobSasTokenUrl = jest . fn ( ( ) => sasURL ) as any ;
6668 FunctionAppService . prototype . get = jest . fn ( ( ) => appStub ) as any ;
69+ unlinkSpy = jest . spyOn ( fs , "unlinkSync" ) ;
6770 } ) ;
6871
6972 afterEach ( ( ) => {
7073 mockFs . restore ( ) ;
74+ unlinkSpy . mockRestore ( ) ;
7175 jest . resetAllMocks ( ) ;
7276 } ) ;
7377
@@ -94,6 +98,11 @@ describe("Rollback Service", () => {
9498 } ) ;
9599
96100 it ( "should deploy blob package directly to function app" , async ( ) => {
101+ const fsConfig = { } ;
102+ fsConfig [ artifactPath ] = "contents" ;
103+ // Mocking the existence of the downloaded artifact because the downloadBinary
104+ // method won't write to the mock file system
105+ mockFs ( fsConfig ) ;
97106 const service = createService ( ) ;
98107 await service . rollback ( ) ;
99108 expect ( AzureBlobStorageService . prototype . initialize ) . toBeCalled ( ) ;
@@ -107,7 +116,8 @@ describe("Rollback Service", () => {
107116 expect ( FunctionAppService . prototype . uploadZippedArfifactToFunctionApp ) . toBeCalledWith (
108117 appStub ,
109118 artifactPath
110- )
119+ ) ;
120+ expect ( unlinkSpy ) . toBeCalledWith ( artifactPath ) ;
111121 } ) ;
112122
113123 it ( "should deploy function app with SAS URL" , async ( ) => {
@@ -133,5 +143,6 @@ describe("Rollback Service", () => {
133143 ) ;
134144 expect ( FunctionAppService . prototype . get ) . not . toBeCalled ( ) ;
135145 expect ( FunctionAppService . prototype . uploadZippedArfifactToFunctionApp ) . not . toBeCalled ( ) ;
146+ expect ( unlinkSpy ) . not . toBeCalled ( ) ;
136147 } ) ;
137148} ) ;
0 commit comments