@@ -5,6 +5,7 @@ import { ArmDeployment } from "../models/armTemplates";
5
5
import { DeploymentConfig } from "../models/serverless" ;
6
6
import { MockFactory } from "../test/mockFactory" ;
7
7
import { RollbackService } from "./rollbackService" ;
8
+ import fs from "fs" ;
8
9
9
10
jest . mock ( "./azureBlobStorageService" ) ;
10
11
import { AzureBlobStorageService } from "./azureBlobStorageService" ;
@@ -31,9 +32,10 @@ describe("Rollback Service", () => {
31
32
const containerName = "deployment-artifacts" ;
32
33
const artifactName = MockFactory . createTestDeployment ( ) . name . replace (
33
34
configConstants . naming . suffix . deployment , configConstants . naming . suffix . artifact ) + ".zip" ;
34
- const artifactPath = `.serverless ${ path . sep } ${ artifactName } `
35
+ const artifactPath = path . join ( ".serverless" , artifactName ) ;
35
36
const armDeployment : ArmDeployment = { template, parameters } ;
36
37
const deploymentString = "deployments" ;
38
+ let unlinkSpy : jest . SpyInstance ;
37
39
38
40
function createOptions ( timestamp ?: string ) : Serverless . Options {
39
41
return {
@@ -64,10 +66,12 @@ describe("Rollback Service", () => {
64
66
ResourceService . prototype . listDeployments = jest . fn ( ( ) => Promise . resolve ( deploymentString ) )
65
67
AzureBlobStorageService . prototype . generateBlobSasTokenUrl = jest . fn ( ( ) => sasURL ) as any ;
66
68
FunctionAppService . prototype . get = jest . fn ( ( ) => appStub ) as any ;
69
+ unlinkSpy = jest . spyOn ( fs , "unlinkSync" ) ;
67
70
} ) ;
68
71
69
72
afterEach ( ( ) => {
70
73
mockFs . restore ( ) ;
74
+ unlinkSpy . mockRestore ( ) ;
71
75
jest . resetAllMocks ( ) ;
72
76
} ) ;
73
77
@@ -94,6 +98,11 @@ describe("Rollback Service", () => {
94
98
} ) ;
95
99
96
100
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 ) ;
97
106
const service = createService ( ) ;
98
107
await service . rollback ( ) ;
99
108
expect ( AzureBlobStorageService . prototype . initialize ) . toBeCalled ( ) ;
@@ -107,7 +116,8 @@ describe("Rollback Service", () => {
107
116
expect ( FunctionAppService . prototype . uploadZippedArfifactToFunctionApp ) . toBeCalledWith (
108
117
appStub ,
109
118
artifactPath
110
- )
119
+ ) ;
120
+ expect ( unlinkSpy ) . toBeCalledWith ( artifactPath ) ;
111
121
} ) ;
112
122
113
123
it ( "should deploy function app with SAS URL" , async ( ) => {
@@ -133,5 +143,6 @@ describe("Rollback Service", () => {
133
143
) ;
134
144
expect ( FunctionAppService . prototype . get ) . not . toBeCalled ( ) ;
135
145
expect ( FunctionAppService . prototype . uploadZippedArfifactToFunctionApp ) . not . toBeCalled ( ) ;
146
+ expect ( unlinkSpy ) . not . toBeCalled ( ) ;
136
147
} ) ;
137
148
} ) ;
0 commit comments