8
8
9
9
import requests
10
10
11
+ SLEEP_TIME = 2
12
+ DEFUALT_1P_ENTRYPOINT = "/lambda-entrypoint.sh"
13
+
11
14
class TestEndToEnd (TestCase ):
12
15
13
16
@classmethod
@@ -33,23 +36,23 @@ def tearDownClass(cls):
33
36
34
37
35
38
def test_env_var_with_eqaul_sign (self ):
36
- cmd = f"docker run --name envvarcheck -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9003:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } /bootstrap-with-handler main.check_env_var_handler"
39
+ cmd = f"docker run --name envvarcheck -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9003:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } { DEFUALT_1P_ENTRYPOINT } main.check_env_var_handler"
37
40
38
41
Popen (cmd .split (' ' )).communicate ()
39
42
40
43
# sleep 1s to give enough time for the endpoint to be up to curl
41
- time .sleep (1 )
44
+ time .sleep (SLEEP_TIME )
42
45
43
46
r = requests .post ("http://localhost:9003/2015-03-31/functions/function/invocations" , json = {})
44
47
self .assertEqual (b'"4=4"' , r .content )
45
48
46
49
def test_two_invokes (self ):
47
- cmd = f"docker run --name testing -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } /bootstrap-with-handler main.success_handler"
50
+ cmd = f"docker run --name testing -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } { DEFUALT_1P_ENTRYPOINT } main.success_handler"
48
51
49
52
Popen (cmd .split (' ' )).communicate ()
50
53
51
54
# sleep 1s to give enough time for the endpoint to be up to curl
52
- time .sleep (1 )
55
+ time .sleep (SLEEP_TIME )
53
56
54
57
r = requests .post ("http://localhost:9000/2015-03-31/functions/function/invocations" , json = {})
55
58
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
@@ -60,23 +63,23 @@ def test_two_invokes(self):
60
63
61
64
62
65
def test_timeout_invoke (self ):
63
- cmd = f"docker run --name timeout -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v { self .path_to_binary } :/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } /bootstrap-with-handler main.sleep_handler"
66
+ cmd = f"docker run --name timeout -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v { self .path_to_binary } :/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } { DEFUALT_1P_ENTRYPOINT } main.sleep_handler"
64
67
65
68
Popen (cmd .split (' ' )).communicate ()
66
69
67
70
# sleep 1s to give enough time for the endpoint to be up to curl
68
- time .sleep (1 )
71
+ time .sleep (SLEEP_TIME )
69
72
70
73
r = requests .post ("http://localhost:9001/2015-03-31/functions/function/invocations" , json = {})
71
74
self .assertEqual (b"Task timed out after 1.00 seconds" , r .content )
72
75
73
76
def test_exception_returned (self ):
74
- cmd = f"docker run --name exception -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9002:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } /bootstrap-with-handler main.exception_handler"
77
+ cmd = f"docker run --name exception -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9002:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } { DEFUALT_1P_ENTRYPOINT } main.exception_handler"
75
78
76
79
Popen (cmd .split (' ' )).communicate ()
77
80
78
81
# sleep 1s to give enough time for the endpoint to be up to curl
79
- time .sleep (1 )
82
+ time .sleep (SLEEP_TIME )
80
83
81
84
r = requests .post ("http://localhost:9002/2015-03-31/functions/function/invocations" , json = {})
82
85
self .assertEqual (b'{"errorMessage": "Raising an exception", "errorType": "Exception", "stackTrace": [" File \\ "/var/task/main.py\\ ", line 13, in exception_handler\\ n raise Exception(\\ "Raising an exception\\ ")\\ n"]}' , r .content )
@@ -105,23 +108,23 @@ def tearDownClass(cls):
105
108
Popen (f"docker rmi { cls .image_name } " .split (' ' )).communicate ()
106
109
107
110
def test_invoke_with_pre_runtime_api_runtime (self ):
108
- cmd = f"docker run --name testing -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } /bootstrap-with-handler main.success_handler"
111
+ cmd = f"docker run --name testing -d -v { self .path_to_binary } :/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } { DEFUALT_1P_ENTRYPOINT } main.success_handler"
109
112
110
113
Popen (cmd .split (' ' )).communicate ()
111
114
112
115
# sleep 1s to give enough time for the endpoint to be up to curl
113
- time .sleep (1 )
116
+ time .sleep (SLEEP_TIME )
114
117
115
118
r = requests .post ("http://localhost:9000/2015-03-31/functions/function/invocations" , json = {})
116
119
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
117
120
118
121
def test_function_name_is_overriden (self ):
119
- cmd = f"docker run --name assert-overwritten -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v { self .path_to_binary } :/local-lambda-runtime-server -p 9009:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } /bootstrap-with-handler main.assert_env_var_is_overwritten"
122
+ cmd = f"docker run --name assert-overwritten -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v { self .path_to_binary } :/local-lambda-runtime-server -p 9009:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie { self .image_name } { DEFUALT_1P_ENTRYPOINT } main.assert_env_var_is_overwritten"
120
123
121
124
Popen (cmd .split (' ' )).communicate ()
122
125
123
126
# sleep 1s to give enough time for the endpoint to be up to curl
124
- time .sleep (1 )
127
+ time .sleep (SLEEP_TIME )
125
128
126
129
r = requests .post ("http://localhost:9009/2015-03-31/functions/function/invocations" , json = {})
127
130
self .assertEqual (b'"My lambda ran succesfully"' , r .content )
0 commit comments