Skip to content

Commit

Permalink
Merge pull request #70 from ijin/node
Browse files Browse the repository at this point in the history
nodejs4.3 runtime support
  • Loading branch information
marcy-terui committed Mar 3, 2017
2 parents a2136ad + 62fbe7b commit c662a53
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ coverage.xml

.venv
*.zip
### https://raw.github.com/github/gitignore/be3333655bffe9507d66cc864aee95ed6052b4ed/Global/vim.gitignore

[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~


7 changes: 6 additions & 1 deletion lamvery/clients/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import botocore
import hashlib
import lamvery.config

from lamvery.clients.base import BaseClient
from lamvery.utils import previous_alias
Expand All @@ -26,10 +27,13 @@ def get_function_conf(self, name, alias=None):
except botocore.exceptions.ClientError:
return {}

def _get_runtime(self, conf):
return lamvery.config.DEFAULT_RUNTIME_NODE_JS if conf['runtime'] == 'nodejs' else conf['runtime']

def create_function(self, zipfile, conf, publish):
kwargs = {}
kwargs['FunctionName'] = conf['name']
kwargs['Runtime'] = conf['runtime']
kwargs['Runtime'] = self._get_runtime(conf)
kwargs['Role'] = conf['role']
kwargs['Handler'] = conf['handler']
kwargs['Code'] = {'ZipFile': zipfile.read()}
Expand Down Expand Up @@ -76,6 +80,7 @@ def update_function_code(self, zipfile, conf, publish):
def update_function_conf(self, conf):
kwargs = {}
kwargs['FunctionName'] = conf['name']
kwargs['Runtime'] = self._get_runtime(conf)
kwargs['Role'] = conf['role']
kwargs['Handler'] = conf['handler']

Expand Down
10 changes: 8 additions & 2 deletions lamvery/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

RUNTIME_PY_27 = 'python2.7'
RUNTIME_NODE_JS = 'nodejs'
RUNTIME_NODE_JS_43 = 'nodejs4.3'
DEFAULT_RUNTIME_NODE_JS = RUNTIME_NODE_JS_43

RUNTIME_AND_EXTENSION = {
RUNTIME_PY_27: 'py',
RUNTIME_NODE_JS: 'js'
RUNTIME_NODE_JS: 'js',
RUNTIME_NODE_JS_43: 'js'
}


Expand Down Expand Up @@ -118,7 +121,10 @@ def unescape(self, txt):
return txt

def get_configuration(self):
return self.load_conf().get('configuration')
config = self.load_conf().get('configuration')
if config['runtime'] == 'nodejs':
config['runtime'] = DEFAULT_RUNTIME_NODE_JS
return config

def get_vpc_configuration(self):
vpc_config = self.get_configuration().get('vpc_config')
Expand Down
8 changes: 8 additions & 0 deletions tests/lamvery/clients/function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
}
}

NODE_CONF = dict(TEST_CONF, runtime='nodejs')
NODE43_CONF = dict(TEST_CONF, runtime='nodejs4.3')


class LambdaClientTestCase(TestCase):

Expand All @@ -36,6 +39,11 @@ def test_get_function_conf(self):
side_effect=botocore.exceptions.ClientError({'Error': {}}, 'bar'))
eq_(self.client.get_function_conf('test'), {})

def test_get_runtime(self):
eq_(self.client._get_runtime(TEST_CONF), 'python2.7')
eq_(self.client._get_runtime(NODE_CONF), 'nodejs4.3')
eq_(self.client._get_runtime(NODE43_CONF), 'nodejs4.3')

def test_create_function(self):
self.client.create_function(Mock(), TEST_CONF, True)

Expand Down
17 changes: 15 additions & 2 deletions tests/lamvery/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"""

NODE_CONF = DEFAULT_CONF.replace('python2.7', 'nodejs')
NODE43_CONF = DEFAULT_CONF.replace('python2.7', 'nodejs4.3')


class FunctionsTestCase(TestCase):
Expand Down Expand Up @@ -156,6 +157,16 @@ def test_get_runtime(self):
config = Config(self.conf_file)
eq_(config.get_runtime(), 'python2.7')

open(self.conf_file, 'w').write(NODE_CONF)
config = Config(self.conf_file)
runtime = config.get_configuration().get('runtime')
eq_(runtime, 'nodejs4.3')

open(self.conf_file, 'w').write(NODE43_CONF)
config = Config(self.conf_file)
runtime = config.get_configuration().get('runtime')
eq_(runtime, 'nodejs4.3')

def test_get_handler(self):
config = Config(self.conf_file)
eq_(config.get_handler(), 'lambda_function.lambda_handler')
Expand Down Expand Up @@ -199,8 +210,10 @@ def test_get_function_filename(self):

open(self.conf_file, 'w').write(NODE_CONF)
config = Config(self.conf_file)
runtime = config.get_configuration().get('runtime')
eq_(runtime, 'nodejs')
eq_(config.get_function_filename(), 'lambda_function.js')

open(self.conf_file, 'w').write(NODE43_CONF)
config = Config(self.conf_file)
eq_(config.get_function_filename(), 'lambda_function.js')

def test_get_archive_name(self):
Expand Down

0 comments on commit c662a53

Please sign in to comment.