@@ -36,6 +36,7 @@ describe("planner", () => {
3636 runtime : "nodejs16" ,
3737 entryPoint : "function" ,
3838 environmentVariables : { } ,
39+ state : "ACTIVE" ,
3940 } as backend . Endpoint ;
4041 }
4142
@@ -137,7 +138,98 @@ describe("planner", () => {
137138 } ) ;
138139 } ) ;
139140
140- describe ( "calculateRegionalChanges" , ( ) => {
141+ describe ( "toSkipPredicate" , ( ) => {
142+ it ( "should skip functions with matching hashes" , ( ) => {
143+ const wantFn = func ( "skip" , "region" ) ;
144+ const haveFn = func ( "skip" , "region" ) ;
145+ wantFn . hash = "same-hash" ;
146+ haveFn . hash = "same-hash" ;
147+
148+ const want = { skip : wantFn } ;
149+ const have = { skip : haveFn } ;
150+
151+ const result = planner . calculateChangesets ( want , have , ( e ) => e . region ) ;
152+
153+ expect ( result . region . endpointsToSkip ) . to . have . lengthOf ( 1 ) ;
154+ expect ( result . region . endpointsToSkip [ 0 ] . id ) . to . equal ( "skip" ) ;
155+ } ) ;
156+
157+ it ( "should not skip functions with different hashes" , ( ) => {
158+ const funcWant = func ( "func" , "region" ) ;
159+ const funcHave = func ( "func" , "region" ) ;
160+ funcWant . hash = "local-hash" ;
161+ funcHave . hash = "server-hash" ;
162+
163+ const want = { func : funcWant } ;
164+ const have = { func : funcHave } ;
165+
166+ const result = planner . calculateChangesets ( want , have , ( e ) => e . region ) ;
167+
168+ expect ( result . region . endpointsToSkip ) . to . have . lengthOf ( 0 ) ;
169+ expect ( result . region . endpointsToUpdate ) . to . have . lengthOf ( 1 ) ;
170+ expect ( result . region . endpointsToUpdate [ 0 ] . endpoint . id ) . to . equal ( "func" ) ;
171+ } ) ;
172+
173+ it ( "should not skip functions with missing hash values" , ( ) => {
174+ const func1Want = func ( "func1" , "region" ) ;
175+ const func1Have = func ( "func1" , "region" ) ;
176+ func1Want . hash = "hash" ;
177+ // func1Have has no hash
178+
179+ const func2Want = func ( "func2" , "region" ) ;
180+ const func2Have = func ( "func2" , "region" ) ;
181+ // func2Want has no hash
182+ func2Have . hash = "hash" ;
183+
184+ // Neither has hash
185+ const func3Want = func ( "func3" , "region" ) ;
186+ const func3Have = func ( "func3" , "region" ) ;
187+
188+ const want = { func1 : func1Want , func2 : func2Want , func3 : func3Want } ;
189+ const have = { func1 : func1Have , func2 : func2Have , func3 : func3Have } ;
190+
191+ const result = planner . calculateChangesets ( want , have , ( e ) => e . region ) ;
192+
193+ expect ( result . region . endpointsToSkip ) . to . have . lengthOf ( 0 ) ;
194+ expect ( result . region . endpointsToUpdate ) . to . have . lengthOf ( 3 ) ;
195+ } ) ;
196+
197+ it ( "should not skip functions targeted by --only flag" , ( ) => {
198+ const funcWant = func ( "func" , "region" ) ;
199+ const funcHave = func ( "func" , "region" ) ;
200+ funcWant . hash = "same-hash" ;
201+ funcHave . hash = "same-hash" ;
202+ funcWant . targetedByOnly = true ;
203+
204+ const want = { func : funcWant } ;
205+ const have = { func : funcHave } ;
206+
207+ const result = planner . calculateChangesets ( want , have , ( e ) => e . region ) ;
208+
209+ expect ( result . region . endpointsToSkip ) . to . have . lengthOf ( 0 ) ;
210+ expect ( result . region . endpointsToUpdate ) . to . have . lengthOf ( 1 ) ;
211+ expect ( result . region . endpointsToUpdate [ 0 ] . endpoint . id ) . to . equal ( "func" ) ;
212+ } ) ;
213+
214+ it ( "should not skip functions in broken state" , ( ) => {
215+ const funcWant = func ( "func" , "region" ) ;
216+ const funcHave = func ( "func" , "region" ) ;
217+ funcWant . hash = "same-hash" ;
218+ funcHave . hash = "same-hash" ;
219+ funcHave . state = "FAILED" ;
220+
221+ const want = { func : funcWant } ;
222+ const have = { func : funcHave } ;
223+
224+ const result = planner . calculateChangesets ( want , have , ( e ) => e . region ) ;
225+
226+ expect ( result . region . endpointsToSkip ) . to . have . lengthOf ( 0 ) ;
227+ expect ( result . region . endpointsToUpdate ) . to . have . lengthOf ( 1 ) ;
228+ expect ( result . region . endpointsToUpdate [ 0 ] . endpoint . id ) . to . equal ( "func" ) ;
229+ } ) ;
230+ } ) ;
231+
232+ describe ( "calculateChangesets" , ( ) => {
141233 it ( "passes a smoke test" , ( ) => {
142234 const created = func ( "created" , "region" ) ;
143235 const updated = func ( "updated" , "region" ) ;
@@ -291,6 +383,24 @@ describe("planner", () => {
291383 } ,
292384 } ) ;
293385 } ) ;
386+
387+ it ( "logs a message when skipping functions" , ( ) => {
388+ // Create functions with matching hashes that will be skipped
389+ const skipWant = func ( "skip" , "region" ) ;
390+ const skipHave = func ( "skip" , "region" ) ;
391+ skipWant . hash = "hash" ;
392+ skipHave . hash = "hash" ;
393+
394+ const want = { skip : skipWant } ;
395+ const have = { skip : skipHave } ;
396+
397+ planner . calculateChangesets ( want , have , ( e ) => e . region ) ;
398+
399+ expect ( logLabeledBullet ) . to . have . been . calledWith (
400+ "functions" ,
401+ "Skipping the deploy of unchanged functions." ,
402+ ) ;
403+ } ) ;
294404 } ) ;
295405
296406 describe ( "createDeploymentPlan" , ( ) => {
0 commit comments