-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
test_command.py
246 lines (227 loc) · 11.5 KB
/
test_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import unittest
from unittest.mock import Mock, patch
from samcli.commands.remote.test_event.get.core.command import RemoteTestEventGetCommand
from samcli.commands.remote.test_event.list.core.command import RemoteTestEventListCommand
from samcli.commands.remote.test_event.delete.core.command import RemoteTestEventDeleteCommand
from samcli.commands.remote.test_event.put.core.command import RemoteTestEventPutCommand
from samcli.commands.remote.test_event.get.cli import DESCRIPTION
from tests.unit.cli.test_command import MockFormatter
class MockParams:
def __init__(self, rv, name):
self.rv = rv
self.name = name
def get_help_record(self, ctx):
return self.rv
class TestRemoteTestEventGetCommand(unittest.TestCase):
@patch.object(RemoteTestEventGetCommand, "get_params")
def test_get_options_remote_invoke_command_text(self, mock_get_params):
ctx = Mock()
ctx.command_path = "sam remote test-event get"
ctx.parent.command_path = "sam"
formatter = MockFormatter(scrub_text=True)
# NOTE: One option per option section.
mock_get_params.return_value = [
MockParams(rv=("--region", "Region"), name="region"),
MockParams(rv=("--stack-name", ""), name="stack_name"),
MockParams(rv=("--parameter", ""), name="parameter"),
MockParams(rv=("--name", ""), name="name"),
MockParams(rv=("--config-file", ""), name="config_file"),
MockParams(rv=("--beta-features", ""), name="beta_features"),
MockParams(rv=("--debug", ""), name="debug"),
]
cmd = RemoteTestEventGetCommand(
name="remote test-event get", requires_credentials=True, description=DESCRIPTION
)
expected_output = {
"Description": [(cmd.description + cmd.description_addendum, "")],
"Examples": [],
"Get a test event from default Lambda function": [
("", ""),
("$ sam remote test-event get --stack-name hello-world --name MyEvent\x1b[0m", ""),
],
"Get a test event for a named Lambda function in the stack": [
("", ""),
("$ sam remote test-event get --stack-name hello-world HelloWorldFunction --name MyEvent\x1b[0m", ""),
],
"Get a test event for a named Lambda function in the stack and save the result to a file": [
("", ""),
(
"$ sam remote test-event get --stack-name hello-world HelloWorldFunction --name MyEvent --output-file my-event.json\x1b[0m",
"",
),
],
"Get a test event for a function using the Lambda ARN": [
("", ""),
(
"$ sam remote test-event get arn:aws:lambda:us-west-2:123456789012:function:my-function --name MyEvent\x1b[0m",
"",
),
],
"Acronyms": [("ARN", "")],
"Infrastructure Options": [("", ""), ("--stack-name", ""), ("", "")],
"Test Event Options": [("", ""), ("--name", ""), ("", "")],
"AWS Credential Options": [("", ""), ("--region", ""), ("", "")],
"Configuration Options": [("", ""), ("--config-file", ""), ("", "")],
"Beta Options": [("", ""), ("--beta-features", ""), ("", "")],
"Other Options": [("", ""), ("--debug", ""), ("", "")],
}
cmd.format_options(ctx, formatter)
self.assertEqual(formatter.data, expected_output)
class TestRemoteTestEventPutCommand(unittest.TestCase):
@patch.object(RemoteTestEventPutCommand, "get_params")
def test_put_options_remote_invoke_command_text(self, mock_get_params):
ctx = Mock()
ctx.command_path = "sam remote test-event put"
ctx.parent.command_path = "sam"
formatter = MockFormatter(scrub_text=True)
# NOTE: One option per option section.
mock_get_params.return_value = [
MockParams(rv=("--region", "Region"), name="region"),
MockParams(rv=("--stack-name", ""), name="stack_name"),
MockParams(rv=("--parameter", ""), name="parameter"),
MockParams(rv=("--name", ""), name="name"),
MockParams(rv=("--config-file", ""), name="config_file"),
MockParams(rv=("--beta-features", ""), name="beta_features"),
MockParams(rv=("--debug", ""), name="debug"),
]
cmd = RemoteTestEventPutCommand(
name="remote test-event get", requires_credentials=True, description=DESCRIPTION
)
expected_output = {
"Description": [(cmd.description + cmd.description_addendum, "")],
"Examples": [],
"Put a remote test event for default Lambda function using the contents of a file": [
("", ""),
(
"$ sam remote test-event put --stack-name hello-world --name MyEvent --file /path/to/event.json\x1b[0m",
"",
),
],
"Put a remote test event for a named Lambda function using the contents of a file": [
("", ""),
(
"$ sam remote test-event put --stack-name hello-world HelloWorldFunction --name MyEvent --file /path/to/event.json\x1b[0m",
"",
),
],
"Put a remote test event for a named Lambda function with stdin input": [
("", ""),
(
'$ echo \'{"message": "hello!"}\' | sam remote test-event put --stack-name hello-world HelloWorldFunction --name MyEvent --file -\x1b[0m',
"",
),
],
"Put a test event for a function using the Lambda ARN using the contents of a file": [
("", ""),
(
"$ sam remote test-event put arn:aws:lambda:us-west-2:123456789012:function:my-function --name MyEvent --file /path/to/event.json\x1b[0m",
"",
),
],
"Acronyms": [("ARN", "")],
"Infrastructure Options": [("", ""), ("--stack-name", ""), ("", "")],
"Test Event Options": [("", ""), ("--name", ""), ("", "")],
"AWS Credential Options": [("", ""), ("--region", ""), ("", "")],
"Configuration Options": [("", ""), ("--config-file", ""), ("", "")],
"Beta Options": [("", ""), ("--beta-features", ""), ("", "")],
"Other Options": [("", ""), ("--debug", ""), ("", "")],
}
cmd.format_options(ctx, formatter)
self.assertEqual(formatter.data, expected_output)
class TestRemoteTestEventListCommand(unittest.TestCase):
@patch.object(RemoteTestEventListCommand, "get_params")
def test_get_options_remote_invoke_command_text(self, mock_get_params):
ctx = Mock()
ctx.command_path = "sam remote test-event list"
ctx.parent.command_path = "sam"
formatter = MockFormatter(scrub_text=True)
# NOTE: One option per option section.
mock_get_params.return_value = [
MockParams(rv=("--region", "Region"), name="region"),
MockParams(rv=("--stack-name", ""), name="stack_name"),
MockParams(rv=("--parameter", ""), name="parameter"),
MockParams(rv=("--config-file", ""), name="config_file"),
MockParams(rv=("--beta-features", ""), name="beta_features"),
MockParams(rv=("--debug", ""), name="debug"),
]
cmd = RemoteTestEventListCommand(
name="remote test-event list", requires_credentials=True, description=DESCRIPTION
)
expected_output = {
"Description": [(cmd.description + cmd.description_addendum, "")],
"Examples": [],
"List remote test events for default Lambda function": [
("", ""),
("$ sam remote test-event list --stack-name hello-world\x1b[0m", ""),
],
"List remote test events for a named Lambda function in the stack": [
("", ""),
("$ sam remote test-event list --stack-name hello-world HelloWorldFunction\x1b[0m", ""),
],
"List remote test events for a function using Lambda ARN": [
("", ""),
(
"$ sam remote test-event list arn:aws:lambda:us-west-2:123456789012:function:my-function\x1b[0m",
"",
),
],
"Acronyms": [("ARN", "")],
"Infrastructure Options": [("", ""), ("--stack-name", ""), ("", "")],
"AWS Credential Options": [("", ""), ("--region", ""), ("", "")],
"Configuration Options": [("", ""), ("--config-file", ""), ("", "")],
"Beta Options": [("", ""), ("--beta-features", ""), ("", "")],
"Other Options": [("", ""), ("--debug", ""), ("", "")],
}
cmd.format_options(ctx, formatter)
self.assertEqual(formatter.data, expected_output)
class TestRemoteTestEventDeleteCommand(unittest.TestCase):
@patch.object(RemoteTestEventDeleteCommand, "get_params")
def test_get_options_remote_invoke_command_text(self, mock_get_params):
ctx = Mock()
ctx.command_path = "sam remote test-event delete"
ctx.parent.command_path = "sam"
formatter = MockFormatter(scrub_text=True)
# NOTE: One option per option section.
mock_get_params.return_value = [
MockParams(rv=("--region", "Region"), name="region"),
MockParams(rv=("--stack-name", ""), name="stack_name"),
MockParams(rv=("--parameter", ""), name="parameter"),
MockParams(rv=("--name", ""), name="name"),
MockParams(rv=("--config-file", ""), name="config_file"),
MockParams(rv=("--beta-features", ""), name="beta_features"),
MockParams(rv=("--debug", ""), name="debug"),
]
cmd = RemoteTestEventDeleteCommand(
name="remote test-event delete", requires_credentials=True, description=DESCRIPTION
)
expected_output = {
"Description": [(cmd.description + cmd.description_addendum, "")],
"Examples": [],
"Delete a test event from default Lambda function": [
("", ""),
("$ sam remote test-event delete --stack-name hello-world --name MyEvent\x1b[0m", ""),
],
"Delete a test event for a named Lambda function in the stack": [
("", ""),
(
"$ sam remote test-event delete --stack-name hello-world HelloWorldFunction --name MyEvent\x1b[0m",
"",
),
],
"Delete a test event for a function using the Lambda ARN": [
("", ""),
(
"$ sam remote test-event delete arn:aws:lambda:us-west-2:123456789012:function:my-function --name MyEvent\x1b[0m",
"",
),
],
"Acronyms": [("ARN", "")],
"Infrastructure Options": [("", ""), ("--stack-name", ""), ("", "")],
"Test Event Options": [("", ""), ("--name", ""), ("", "")],
"AWS Credential Options": [("", ""), ("--region", ""), ("", "")],
"Configuration Options": [("", ""), ("--config-file", ""), ("", "")],
"Beta Options": [("", ""), ("--beta-features", ""), ("", "")],
"Other Options": [("", ""), ("--debug", ""), ("", "")],
}
cmd.format_options(ctx, formatter)
self.assertEqual(formatter.data, expected_output)