Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trailing newline when writing a jsonnetfile.json #393

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commodore/component/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def render_jsonnetfile_json(self, component_params):
)
with open(self._dir / "jsonnetfile.json", "w", encoding="utf-8") as fp:
fp.write(output)
fp.write("\n")


def component_dir(work_dir: P, name: str) -> P:
Expand Down
2 changes: 2 additions & 0 deletions commodore/dependency_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def write_jsonnetfile(file: P, deps: Iterable):

with open(file, "w", encoding="utf-8") as f:
f.write(json.dumps(data, indent=4))
f.write("\n")


def fetch_jsonnet_libraries(cwd: P, deps: Iterable = None):
Expand Down Expand Up @@ -243,6 +244,7 @@ def inject_essential_libraries(file: P):

with open(file, "w", encoding="utf-8") as j:
json.dump(data, j, indent=4)
j.write("\n")


def register_components(cfg: Config):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_component_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ def test_run_component_compile_command(tmp_path: P):

assert list(component_repo.remote().urls) == orig_remote_urls

jfpath = P(component_repo.working_tree_dir, "jsonnetfile.json")
assert jfpath.exists()
with open(jfpath) as jf:
jfstring = jf.read()
assert jfstring[-1] == "\n"


def test_run_component_compile_command_postprocess(tmp_path):
"""
Expand Down
25 changes: 24 additions & 1 deletion tests/test_dependency_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,37 @@ def test_write_jsonnetfile(data: Config, tmp_path: Path):
dependency_mgmt.write_jsonnetfile(file, dependency_mgmt.jsonnet_dependencies(data))

with open(file) as jf:
jf_contents = json.load(jf)
jf_string = jf.read()
assert jf_string[-1] == "\n"
jf_contents = json.loads(jf_string)
assert jf_contents["version"] == 1
assert jf_contents["legacyImports"]
deps = jf_contents["dependencies"]
for dep in deps:
assert dep["source"]["local"]["directory"] in dirs


def test_inject_essential_libraries(tmp_path: Path):
file = tmp_path / "jsonnetfile.json"
dependency_mgmt.write_jsonnetfile(file, [])

dependency_mgmt.inject_essential_libraries(file)

with open(file) as jf:
jf_string = jf.read()
assert jf_string[-1] == "\n"
jf_contents = json.loads(jf_string)
assert jf_contents["version"] == 1
assert jf_contents["legacyImports"]
deps = jf_contents["dependencies"]
assert len(deps) == 1
assert (
deps[0]["source"]["git"]["remote"]
== "https://github.com/bitnami-labs/kube-libsonnet"
)
assert deps[0]["version"] == "v1.14.6"


def test_clear_jsonnet_lock_file(tmp_path: Path):
jsonnetfile = tmp_path / "jsonnetfile.json"
jsonnet_lock = tmp_path / "jsonnetfile.lock.json"
Expand Down