-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import json | ||
|
||
from packerlicious import UserVar, Template | ||
from packerlicious import builder, post_processor, provisioner | ||
|
||
|
||
class TestPackerTemplate(object): | ||
def test_template(self): | ||
t = Template(description="test description", min_packer_version="0.9.0") | ||
|
||
d = t.to_dict() | ||
assert d['description'] == "test description" | ||
assert d['min_packer_version'] == "0.9.0" | ||
|
||
t.add_description("new description") | ||
t.add_min_packer_version("1.0.0") | ||
d = t.to_dict() | ||
assert d['description'] == "new description" | ||
assert d['min_packer_version'] == "1.0.0" | ||
|
||
def test_template_variables(self): | ||
t = Template() | ||
|
||
t.add_variable(UserVar("my_var", "my_value")) | ||
|
||
d = t.to_dict() | ||
assert d['variables'] == {'my_var': 'my_value'} | ||
|
||
def test_template_builders(self): | ||
expected_json = """ | ||
{ | ||
"builders": [ | ||
{ | ||
"source": "/source/path", | ||
"target": "/target/path", | ||
"type": "file" | ||
} | ||
] | ||
} | ||
""" | ||
|
||
t = Template() | ||
t.add_builder(builder.File( | ||
target="/target/path", | ||
source="/source/path", | ||
)) | ||
|
||
to_json = t.to_json() | ||
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, | ||
separators=(',', ': ')) | ||
|
||
def test_template_provisioners(self): | ||
expected_json = """ | ||
{ | ||
"provisioners": [ | ||
{ | ||
"source": "/src/path", | ||
"destination": "/dest/path", | ||
"direction": "upload", | ||
"type": "file" | ||
} | ||
] | ||
} | ||
""" | ||
|
||
t = Template() | ||
t.add_provisioner(provisioner.File( | ||
source="/src/path", | ||
destination="/dest/path", | ||
direction=provisioner.File.Upload, | ||
)) | ||
|
||
to_json = t.to_json() | ||
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, | ||
separators=(',', ': ')) | ||
|
||
def test_template_post_processors(self): | ||
expected_json = """ | ||
{ | ||
"post-processors": [ | ||
{ | ||
"script": "/my/post/script", | ||
"type": "shell-local" | ||
} | ||
] | ||
} | ||
""" | ||
|
||
t = Template() | ||
t.add_post_processor(post_processor.ShellLocal( | ||
script="/my/post/script", | ||
)) | ||
|
||
to_json = t.to_json() | ||
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, | ||
separators=(',', ': ')) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters