-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathtest_ec2.py
32 lines (28 loc) · 1.13 KB
/
test_ec2.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
import pytest
import click
from flintrock.ec2 import validate_tags
def test_validate_tags():
# List of test cases; each test case is a tuple, with first element
# the input and the second element the expected output
positive_test_cases = [
# basic case
(['k1,v1'], [{'Key': 'k1', 'Value': 'v1'}]),
# strips whitespace?
(['k2, v2 '], [{'Key': 'k2', 'Value': 'v2'}]),
# empty Value
(['k3,'], [{'Key': 'k3', 'Value': ''}]),
# multiple tags
(['k4,v4', 'k5,v5'],
[{'Key': 'k4', 'Value': 'v4'}, {'Key': 'k5', 'Value': 'v5'}])]
for test_case in positive_test_cases:
ec2_tags = validate_tags(test_case[0])
assert isinstance(ec2_tags, list)
for i, ec2_tag in enumerate(ec2_tags):
expected_dict = test_case[1][i]
for k in expected_dict:
assert k in ec2_tag
assert ec2_tag[k] == expected_dict[k]
negative_test_cases = [["k1"], ["k2,v2,"], ["k3,,v3"], [",v4"]]
for test_case in negative_test_cases:
with pytest.raises(click.BadParameter):
validate_tags(test_case)