Skip to content

Commit 2eaec5d

Browse files
committed
Merge pull request #80 from rackerlabs/error_checking
Introduce some more testing
2 parents 85701b4 + ba38273 commit 2eaec5d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lambda_uploader/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ def s3_package_name(self):
121121

122122
'''Load config ... called by init()'''
123123
def _load_config(self, lambda_file=None):
124+
if not path.isdir(self._path):
125+
raise Exception("%s not a valid function directory" % self._path)
126+
124127
if not lambda_file:
125128
lambda_file = path.join(self._path, 'lambda.json')
126129

127-
if not path.isfile(lambda_file) or path.isdir(lambda_file):
130+
if not path.isfile(lambda_file):
128131
raise Exception("%s not a valid configuration file" % lambda_file)
129132

130133
with open(lambda_file) as config_file:

test/test_config.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from os import path
22
from lambda_uploader import config
3+
import pytest
34

45
EX_CONFIG = path.normpath(path.join(path.dirname(__file__),
56
'../test/configs'))
@@ -57,6 +58,35 @@ def test_set_publish():
5758

5859

5960
def test___getattr__():
60-
cfg = config.Config(EX_CONFIG, EX_CONFIG + '/lambda.json')
61+
cfg = config.Config(EX_CONFIG, path.join(EX_CONFIG, 'lambda.json'))
6162
assert cfg.s3_bucket is None
6263
assert cfg.name == 'myFunc'
64+
65+
66+
def test_invalid_config_as_dir():
67+
# pass the function directory as the lambda configuration --
68+
# this should not work!
69+
with pytest.raises(Exception):
70+
config.Config(EX_CONFIG, EX_CONFIG)
71+
72+
73+
def test_invalid_config_missing_file():
74+
# try invalid file
75+
with pytest.raises(Exception):
76+
config.Config(EX_CONFIG, path.join(EX_CONFIG, 'pleasedontexist.json'))
77+
78+
79+
def test_invalid_config_missing_function_dir():
80+
# try invalid file
81+
with pytest.raises(Exception):
82+
config.Config(path.join(EX_CONFIG, 'pleasedontexist_dir'))
83+
84+
85+
def test_invalid_config_missing_function_dir2():
86+
with pytest.raises(Exception):
87+
config.Config(
88+
# invalid function dir
89+
path.join(EX_CONFIG, 'pleasedontexist_dir'),
90+
# valid config file
91+
path.join(EX_CONFIG, 'lambda.json')
92+
)

0 commit comments

Comments
 (0)