Skip to content

Commit

Permalink
add tests for packer template
Browse files Browse the repository at this point in the history
  • Loading branch information
mayn committed Aug 14, 2017
1 parent ca7c6a6 commit 91f493e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
99 changes: 99 additions & 0 deletions tests/packerlicious/test_template.py
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=(',', ': '))



2 changes: 1 addition & 1 deletion tests/packerlicious/test_variables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from packerlicious import Ref,EnvVar, TemplateVar, UserVar
from packerlicious import Ref, EnvVar, TemplateVar, UserVar


class TestPackerVariables(object):
Expand Down

0 comments on commit 91f493e

Please sign in to comment.