diff --git a/commodore/component/__init__.py b/commodore/component/__init__.py index cc91aa8c..10a66559 100644 --- a/commodore/component/__init__.py +++ b/commodore/component/__init__.py @@ -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: diff --git a/commodore/dependency_mgmt.py b/commodore/dependency_mgmt.py index 58fd5822..7c370496 100644 --- a/commodore/dependency_mgmt.py +++ b/commodore/dependency_mgmt.py @@ -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): @@ -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): diff --git a/tests/test_component_compile.py b/tests/test_component_compile.py index 390a7aa6..7d75227c 100644 --- a/tests/test_component_compile.py +++ b/tests/test_component_compile.py @@ -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): """ diff --git a/tests/test_dependency_mgmt.py b/tests/test_dependency_mgmt.py index 438945d9..7022363d 100644 --- a/tests/test_dependency_mgmt.py +++ b/tests/test_dependency_mgmt.py @@ -317,7 +317,9 @@ 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"] @@ -325,6 +327,27 @@ def test_write_jsonnetfile(data: Config, tmp_path: Path): 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"