@@ -3,7 +3,11 @@ import * as path from 'path';
33import * as semver from 'semver' ;
44
55import * as loader from '../../src/runtime/loader' ;
6- import { ManifestBackend , ManifestEndpoint } from '../../src/runtime/manifest' ;
6+ import {
7+ ManifestStack ,
8+ ManifestEndpoint ,
9+ ManifestRequiredAPI ,
10+ } from '../../src/runtime/manifest' ;
711
812function annotatedFn (
913 endpoint : ManifestEndpoint
@@ -27,15 +31,16 @@ const EVENT_ENDPOINT = {
2731 } ,
2832} ;
2933
30- describe ( 'extractEndpoints ' , ( ) => {
31- it ( 'extracts endpoints from a simple module' , ( ) => {
34+ describe ( 'extractStack ' , ( ) => {
35+ it ( 'extracts stack from a simple module' , ( ) => {
3236 const module = {
3337 fn1 : annotatedFn ( HTTP_ENDPOINT ) ,
3438 fn2 : annotatedFn ( EVENT_ENDPOINT ) ,
3539 } ;
3640
3741 const endpoints : Record < string , ManifestEndpoint > = { } ;
38- loader . extractEndpoints ( module , endpoints ) ;
42+ const requiredAPIs : Record < string , ManifestRequiredAPI > = { } ;
43+ loader . extractStack ( module , endpoints , requiredAPIs ) ;
3944 expect ( endpoints ) . to . be . deep . equal ( {
4045 fn1 : {
4146 entryPoint : 'fn1' ,
@@ -48,7 +53,7 @@ describe('extractEndpoints', () => {
4853 } ) ;
4954 } ) ;
5055
51- it ( 'extracts endpoints from a module with group functions' , ( ) => {
56+ it ( 'extracts stack from a module with group functions' , ( ) => {
5257 const module = {
5358 fn1 : annotatedFn ( HTTP_ENDPOINT ) ,
5459 g1 : {
@@ -57,7 +62,8 @@ describe('extractEndpoints', () => {
5762 } ;
5863
5964 const endpoints : Record < string , ManifestEndpoint > = { } ;
60- loader . extractEndpoints ( module , endpoints ) ;
65+ const requiredAPIs : Record < string , ManifestRequiredAPI > = { } ;
66+ loader . extractStack ( module , endpoints , requiredAPIs ) ;
6167 expect ( endpoints ) . to . be . deep . equal ( {
6268 fn1 : {
6369 entryPoint : 'fn1' ,
@@ -71,8 +77,8 @@ describe('extractEndpoints', () => {
7177 } ) ;
7278} ) ;
7379
74- describe ( 'loadBackend ' , ( ) => {
75- const expected : ManifestBackend = {
80+ describe ( 'loadStack ' , ( ) => {
81+ const expected : ManifestStack = {
7682 endpoints : {
7783 v1http : {
7884 platform : 'gcfv1' ,
@@ -86,31 +92,32 @@ describe('loadBackend', () => {
8692 callableTrigger : { } ,
8793 } ,
8894 } ,
89- requiredAPIs : { } ,
95+ requiredAPIs : [ ] ,
9096 specVersion : 'v1alpha1' ,
9197 } ;
9298
9399 type Testcase = {
94100 name : string ;
95101 modulePath : string ;
96- expected : ManifestBackend ;
102+ expected : ManifestStack ;
97103 } ;
98104
99105 function runTests ( tc : Testcase ) {
100106 it ( 'loads backend given relative path' , async ( ) => {
101- await expect ( loader . loadBackend ( tc . modulePath ) ) . to . eventually . deep . equal (
107+ await expect ( loader . loadStack ( tc . modulePath ) ) . to . eventually . deep . equal (
102108 tc . expected
103109 ) ;
104110 } ) ;
105111
106112 it ( 'loads backend given absolute path' , async ( ) => {
107113 await expect (
108- loader . loadBackend ( path . join ( process . cwd ( ) , tc . modulePath ) )
114+ loader . loadStack ( path . join ( process . cwd ( ) , tc . modulePath ) )
109115 ) . to . eventually . deep . equal ( tc . expected ) ;
110116 } ) ;
111117 }
112118
113119 let prev ;
120+
114121 beforeEach ( ( ) => {
115122 // TODO: When __trigger annotation is removed and GCLOUD_PROJECT is not required at runtime, remove this.
116123 prev = process . env . GCLOUD_PROJECT ;
@@ -150,7 +157,7 @@ describe('loadBackend', () => {
150157 callableTrigger : { } ,
151158 } ,
152159 } ,
153- requiredAPIs : { } ,
160+ requiredAPIs : [ ] ,
154161 specVersion : 'v1alpha1' ,
155162 } ,
156163 } ,
@@ -170,10 +177,16 @@ describe('loadBackend', () => {
170177 } ,
171178 } ,
172179 } ,
173- requiredAPIs : {
174- pubsub : 'pubsub.googleapis.com' ,
175- scheduler : 'cloudscheduler.googleapis.com' ,
176- } ,
180+ requiredAPIs : [
181+ {
182+ api : 'pubsub.googleapis.com' ,
183+ reason : 'Needed for v1 scheduled functions.' ,
184+ } ,
185+ {
186+ api : 'cloudscheduler.googleapis.com' ,
187+ reason : 'Needed for v1 scheduled functions.' ,
188+ } ,
189+ ] ,
177190 specVersion : 'v1alpha1' ,
178191 } ,
179192 } ,
0 commit comments