@@ -59,6 +59,41 @@ describe('Scf', () => {
5959 inputs
6060 }
6161
62+ const webFuncYaml = {
63+ org : appId ,
64+ app : 'appDemo' ,
65+ component : 'scf@dev' ,
66+ name : `scf-web-integration-tests-${ generateId ( ) } ` ,
67+ stage : 'dev' ,
68+ inputs : {
69+ name : `scf-web-integration-tests-${ generateId ( ) } ` ,
70+ src : {
71+ src : path . join ( __dirname , '../example/web/src' ) ,
72+ exclude : [ '.env' ]
73+ } ,
74+ type : 'web' ,
75+ region : 'ap-chengdu' ,
76+ runtime : 'Nodejs12.16' ,
77+ events : [
78+ {
79+ apigw : {
80+ parameters : {
81+ protocols : [ 'http' , 'https' ] ,
82+ description : 'The service of Serverless Framework' ,
83+ environment : 'test' ,
84+ endpoints : [
85+ {
86+ path : '/' ,
87+ method : 'ANY'
88+ }
89+ ]
90+ }
91+ }
92+ }
93+ ]
94+ }
95+ }
96+
6297 const sdk = getServerlessSdk ( instanceYaml . org , appId )
6398
6499 let lastVersion = '$LATEST'
@@ -370,4 +405,60 @@ describe('Scf', () => {
370405
371406 expect ( result . instance . instanceStatus ) . toEqual ( 'inactive' )
372407 } )
408+
409+ it ( 'deploy web function' , async ( ) => {
410+ const instance = await sdk . deploy ( webFuncYaml , credentials )
411+
412+ expect ( instance ) . toBeDefined ( )
413+ expect ( instance . instanceName ) . toEqual ( webFuncYaml . name )
414+
415+ const { outputs } = instance
416+ // get src from template by default
417+ expect ( outputs . functionName ) . toEqual ( webFuncYaml . inputs . name )
418+ expect ( outputs . runtime ) . toEqual ( webFuncYaml . inputs . runtime )
419+ expect ( outputs . triggers ) . toBeDefined ( )
420+ expect ( outputs . triggers . length ) . toBe ( 1 )
421+
422+ const { triggers } = outputs
423+ const apiTrigger = triggers [ 0 ]
424+
425+ expect ( apiTrigger ) . toEqual ( {
426+ NeedCreate : expect . any ( Boolean ) ,
427+ created : expect . any ( Boolean ) ,
428+ serviceId : expect . stringContaining ( 'service-' ) ,
429+ serviceName : 'serverless' ,
430+ subDomain : expect . stringContaining ( '.cd.apigw.tencentcs.com' ) ,
431+ protocols : 'http&https' ,
432+ environment : 'test' ,
433+ url : expect . stringContaining ( 'http' ) ,
434+ apiList : [
435+ {
436+ created : expect . any ( Boolean ) ,
437+ path : '/' ,
438+ method : 'ANY' ,
439+ apiId : expect . stringContaining ( 'api-' ) ,
440+ apiName : 'index' ,
441+ authType : 'NONE' ,
442+ businessType : 'NORMAL' ,
443+ internalDomain : expect . any ( String ) ,
444+ url : expect . stringContaining ( 'http' ) ,
445+ isBase64Encoded : false
446+ }
447+ ] ,
448+ urls : expect . any ( Array )
449+ } )
450+ } )
451+
452+ it ( 'remove web function' , async ( ) => {
453+ await sleep ( 5000 )
454+ await sdk . remove ( webFuncYaml , credentials )
455+ const result = await sdk . getInstance (
456+ webFuncYaml . org ,
457+ webFuncYaml . stage ,
458+ webFuncYaml . app ,
459+ webFuncYaml . name
460+ )
461+
462+ expect ( result . instance . instanceStatus ) . toEqual ( 'inactive' )
463+ } )
373464} )
0 commit comments