File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,20 @@ describe('code', () => {
16
16
} ) ;
17
17
18
18
describe ( 'lambda.Code.fromAsset' , ( ) => {
19
+ test ( 'fails if path is empty' , ( ) => {
20
+ // GIVEN
21
+ const fileAsset = lambda . Code . fromAsset ( '' ) ;
22
+
23
+ // THEN
24
+ expect ( ( ) => defineFunction ( fileAsset ) ) . toThrow ( / A s s e t p a t h c a n n o t b e e m p t y / ) ;
25
+ } ) ;
26
+ test ( 'fails if path does not exist' , ( ) => {
27
+ // GIVEN
28
+ const fileAsset = lambda . Code . fromAsset ( '/path/not/found/' + Math . random ( ) * 999999 ) ;
29
+
30
+ // THEN
31
+ expect ( ( ) => defineFunction ( fileAsset ) ) . toThrow ( / C a n n o t f i n d a s s e t / ) ;
32
+ } ) ;
19
33
test ( 'fails if a non-zip asset is used' , ( ) => {
20
34
// GIVEN
21
35
const fileAsset = lambda . Code . fromAsset ( path . join ( __dirname , 'my-lambda-handler' , 'index.py' ) ) ;
Original file line number Diff line number Diff line change @@ -137,6 +137,10 @@ export class Asset extends Construct implements cdk.IAsset {
137
137
constructor ( scope : Construct , id : string , props : AssetProps ) {
138
138
super ( scope , id ) ;
139
139
140
+ if ( ! props . path ) {
141
+ throw new Error ( 'Asset path cannot be empty' ) ;
142
+ }
143
+
140
144
this . isBundled = props . bundling != null ;
141
145
142
146
// stage the asset source (conditionally).
Original file line number Diff line number Diff line change @@ -143,11 +143,18 @@ test('"readers" or "grantRead" can be used to grant read permissions on the asse
143
143
} ) ;
144
144
} ) ;
145
145
146
+ test ( 'fails if path is empty' , ( ) => {
147
+ const stack = new cdk . Stack ( ) ;
148
+ expect ( ( ) => new Asset ( stack , 'MyDirectory' , {
149
+ path : '' ,
150
+ } ) ) . toThrow ( / A s s e t p a t h c a n n o t b e e m p t y / ) ;
151
+ } ) ;
152
+
146
153
test ( 'fails if directory not found' , ( ) => {
147
154
const stack = new cdk . Stack ( ) ;
148
155
expect ( ( ) => new Asset ( stack , 'MyDirectory' , {
149
156
path : '/path/not/found/' + Math . random ( ) * 999999 ,
150
- } ) ) . toThrow ( ) ;
157
+ } ) ) . toThrow ( / C a n n o t f i n d a s s e t / ) ;
151
158
} ) ;
152
159
153
160
test ( 'multiple assets under the same parent' , ( ) => {
You can’t perform that action at this time.
0 commit comments