Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed Nov 25, 2024
1 parent 8632b6a commit 9f74c46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,24 @@ def test_get_grpc_plugin_location_with_no_env_no_local_file_failed(self):
result = self._run_command("get_grpc_plugin_location")
self.assertEqual(1, result.returncode)
self.assertRegex(result.stdout.decode(), "Can't find grpc plugin in")

def test_get_formatter_location_with_env_returns_env(self):
os.environ["JAVA_FORMATTER_LOCATION"] = "/java-formatter"
result = self._run_command_and_get_sdout("get_java_formatter_location")
self.assertEqual("/java-formatter", result)
os.environ.pop("JAVA_FORMATTER_LOCATION")

def test_get_formatter_location_without_env_with_local_returns_local(self):
bash_call(
f"touch {self.simulated_home}/.library_generation/google-java-format.jar"
)
result = self._run_command_and_get_sdout("get_java_formatter_location")
self.assertEqual(
f"{self.simulated_home}/.library_generation/google-java-format.jar",
result,
)

def test_get_formatter_location_with_no_env_no_local_file_failed(self):
result = self._run_command("get_java_formatter_location")
self.assertEqual(1, result.returncode)
self.assertRegex(result.stdout.decode(), "Can't find Java formatter in")
2 changes: 1 addition & 1 deletion hermetic_build/library_generation/utils/utilities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ get_grpc_plugin_location() {

get_java_formatter_location() {
local formatter_location
formatter_location="${HOME}"/.library_generation/google-java-format.jar
formatter_location="${HOME}/.library_generation/google-java-format.jar"
if [[ -n "${JAVA_FORMATTER_LOCATION}" ]]; then
echo "${JAVA_FORMATTER_LOCATION}"
elif [[ -f "${formatter_location}" ]]; then
Expand Down

0 comments on commit 9f74c46

Please sign in to comment.