@@ -36,7 +36,65 @@ describe('lib/s3_deploy', () => {
3636 } )
3737 } )
3838
39+ describe ( '_convertRegionStringToEnvVarName' , ( ) => {
40+ it ( 'Upper case. Replace "-" with "_".' , ( ) => {
41+ [ {
42+ value : 'us-west-1' ,
43+ expected : 'US_WEST_1'
44+ } , {
45+ value : 'ap-southeast-2' ,
46+ expected : 'AP_SOUTHEAST_2'
47+ } ] . forEach ( ( test ) => {
48+ assert . equal (
49+ s3Deploy . _convertRegionStringToEnvVarName ( test . value ) ,
50+ test . expected ,
51+ test
52+ )
53+ } )
54+ } )
55+ } )
56+
57+ describe ( '_getBucketNameFromEnvVar' , ( ) => {
58+ after ( ( ) => {
59+ delete process . env . S3_US_WEST_1_BUCKET
60+ } )
61+
62+ it ( 'is undefined' , ( ) => {
63+ assert . isUndefined ( s3Deploy . _getBucketNameFromEnvVar ( 'us-west-1' ) )
64+ } )
65+
66+ it ( 'Get values from environment variables' , ( ) => {
67+ process . env . S3_US_WEST_1_BUCKET = 'bucketName'
68+ assert . equal (
69+ s3Deploy . _getBucketNameFromEnvVar ( 'us-west-1' ) ,
70+ 'bucketName'
71+ )
72+ } )
73+ } )
74+
75+ describe ( '_getS3KeyPrefixFromEnvVar' , ( ) => {
76+ after ( ( ) => {
77+ delete process . env . S3_US_WEST_1_PREFIX
78+ } )
79+
80+ it ( 'is undefined' , ( ) => {
81+ assert . isUndefined ( s3Deploy . _getS3KeyPrefixFromEnvVar ( 'us-west-1' ) )
82+ } )
83+
84+ it ( 'Get values from environment variables' , ( ) => {
85+ process . env . S3_US_WEST_1_PREFIX = 's3KeyPrefix'
86+ assert . equal (
87+ s3Deploy . _getS3KeyPrefixFromEnvVar ( 'us-west-1' ) ,
88+ 's3KeyPrefix'
89+ )
90+ } )
91+ } )
92+
3993 describe ( '_bucketName' , ( ) => {
94+ after ( ( ) => {
95+ delete process . env . S3_TEST_REGION_BUCKET
96+ } )
97+
4098 it ( 'FunctionName + region + md5()' , ( ) => {
4199 const params = {
42100 FunctionName : 'node-lambda-name' ,
@@ -47,16 +105,44 @@ describe('lib/s3_deploy', () => {
47105 'node-lambda-name-test_region-aac849d59d2be828b793609e03d8241d'
48106 )
49107 } )
108+
109+ it ( 'Use environment variables' , ( ) => {
110+ process . env . S3_TEST_REGION_BUCKET = 's3-test-region-bucket'
111+ const params = {
112+ FunctionName : 'node-lambda-name' ,
113+ region : 'test_region'
114+ }
115+ assert . equal ( s3Deploy . _bucketName ( params ) , 's3-test-region-bucket' )
116+ } )
50117 } )
51118
52119 describe ( '_s3Key' , ( ) => {
120+ after ( ( ) => {
121+ delete process . env . S3_TEST_REGION_PREFIX
122+ } )
123+
53124 it ( '"deploy-package" + FunctionName + ".zip"' , ( ) => {
54- const params = { FunctionName : 'node-lambda-name' }
125+ const params = {
126+ FunctionName : 'node-lambda-name' ,
127+ region : 'test_region'
128+ }
55129 assert . equal (
56130 s3Deploy . _s3Key ( params ) ,
57131 'deploy-package-node-lambda-name.zip'
58132 )
59133 } )
134+
135+ it ( 'Use environment variables' , ( ) => {
136+ process . env . S3_TEST_REGION_PREFIX = 's3-test-region-prefix/'
137+ const params = {
138+ FunctionName : 'node-lambda-name' ,
139+ region : 'test_region'
140+ }
141+ assert . equal (
142+ s3Deploy . _s3Key ( params ) ,
143+ 's3-test-region-prefix/deploy-package-node-lambda-name.zip'
144+ )
145+ } )
60146 } )
61147
62148 describe ( '_getS3Location' , ( ) => {
0 commit comments