Skip to content

Commit

Permalink
feat(generator): render here document content
Browse files Browse the repository at this point in the history
  • Loading branch information
fyhertz committed Apr 26, 2022
1 parent 9c0aac0 commit 8cff338
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ops2deb/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ def _populate_with_fetch_result(self, fetch_result: FetchResult) -> None:
else:
shutil.copytree(fetch_result.storage_path, self.fetch_directory)

@classmethod
def _install_here_document(cls, entry: HereDocument, destination: Path) -> None:
def _install_here_document(self, entry: HereDocument, destination: Path) -> None:
if destination.exists():
raise Ops2debGeneratorError(f"Destination {destination} already exists")
destination.write_text(entry.content)
destination.write_text(self.blueprint.render_string(entry.content))

def _install_source_destination_str(
self, entry: SourceDestinationStr, destination: Path
Expand Down
9 changes: 9 additions & 0 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ def test__install_files_should_create_here_document_in_package_directory_if_dest
assert (tmp_path / "great-app_1.0.0_amd64/test").is_file()


def test__install_files_should_render_content_in_here_document(
tmp_path, blueprint_factory
):
files = [dict(path="test", content="{{version}}")]
blueprint = blueprint_factory(install=files)
SourcePackage(blueprint, tmp_path)._install_files()
assert (tmp_path / "great-app_1.0.0_amd64/test").read_text() == blueprint.version


def test__install_files_should_fail_to_create_here_document_if_file_already_exists(
tmp_path, blueprint_factory
):
Expand Down

0 comments on commit 8cff338

Please sign in to comment.