This repository was archived by the owner on Oct 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_utils.py
More file actions
61 lines (47 loc) · 1.79 KB
/
test_utils.py
File metadata and controls
61 lines (47 loc) · 1.79 KB
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
import os
import packer
import testtools
TEST_RESOURCES_DIR = 'tests/resources'
TEST_PACKERFILE = os.path.join(TEST_RESOURCES_DIR, 'simple-test.json')
TEST_BAD_PACKERFILE = os.path.join(TEST_RESOURCES_DIR, 'badpackerfile.json')
PACKER = packer.Packer(TEST_PACKERFILE)
def test_dict_to_command():
"""Validate dict is converted to a command properly"""
kwargs = {'test': 'value'}
cmd = PACKER.dict_to_command(kwargs)
assert cmd == ['--test=value']
def test_join_comma():
"""Validate list concatination is correct"""
output = PACKER._join_comma(['hello', 'world'])
assert output == 'hello,world'
def test_run_command():
"""Check returned output from executed command"""
cmd = ['packer', 'version']
output = PACKER._run_command(cmd)
assert 'Packer v' in output.stdout
assert '' in output.stderr
assert 0 == output.returncode
def test_parse_inspection_output():
"""Check returned output from executed command"""
output = '''1508999535,,ui,say,Variables:
1508999535,,ui,say, <No variables>
1508999535,,ui,say,
1508999535,,ui,say,Builders:
1508999535,,template-builder,docker,docker
1508999535,,ui,say, docker
1508999535,,ui,say,
1508999535,,ui,say,Provisioners:
1508999535,,template-provisioner,shell
1508999535,,ui,say, shell
1508999535,,ui,say,Note: If your build names contain user variables or template functions such as 'timestamp'%!(PACKER_COMMA) these are processed at build time%!(PACKER_COMMA) and therefore only show in their raw form here.'''
output = PACKER._parse_inspection_output(output)
assert {
'builders': [{
'name': 'docker',
'type': 'docker'
}],
'provisioners': [{
'type': 'shell'
}],
'variables': []
} == output