diff --git a/docs/development.md b/docs/development.md index 1c6bde5..75834f9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -70,6 +70,19 @@ All module-internal names are prefixed with an underscore. Such names should not be used from another module. Modules must avoid reaching into each other's internals. +## Testing + +Everything should have a unit test. In this project, we avoid access to the +internet and to the user's cjdk cache directory in all unit tests. Instead, +temporary directories are used to mock the cache, and, where needed, a mock +server is used to test downloads. + +Unit test modules should try not to import cjdk modules other than the one +under test, although sometimes this is unavoidable. + +Actual use of the internet (including the Coursier index) and the user cache +directory is limited to integration tests, which are kept separate. + (versioning-scheme)= ## Versioning diff --git a/tests/test_api.py b/tests/test_api.py index 10f4e91..c32d860 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -154,37 +154,3 @@ def test_env_var_set(): with f("CJDK_TEST_ENV_VAR", "testvalue"): assert os.environ["CJDK_TEST_ENV_VAR"] == "testvalue" assert "CJDK_TEST_ENV_VAR" not in os.environ - - -def test_list_vendors(): - vendors = _api.list_vendors() - assert vendors is not None - assert "adoptium" in vendors - assert "corretto" in vendors - assert "graalvm" in vendors - assert "ibm-semeru-openj9" in vendors - assert "java-oracle" in vendors - assert "liberica" in vendors - assert "temurin" in vendors - assert "zulu" in vendors - - -def test_list_jdks(): - jdks = _api.list_jdks(cached_only=False) - assert jdks is not None - assert "adoptium:1.21.0.4" in jdks - assert "corretto:21.0.4.7.1" in jdks - assert "graalvm-community:21.0.2" in jdks - assert "graalvm-java21:21.0.2" in jdks - assert "liberica:22.0.2" in jdks - assert "temurin:1.21.0.4" in jdks - assert "zulu:8.0.362" in jdks - - cached_jdks = _api.list_jdks() - assert cached_jdks is not None - assert len(cached_jdks) < len(jdks) - - zulu_jdks = _api.list_jdks(vendor="zulu", cached_only=False) - assert zulu_jdks is not None - assert len(set(zulu_jdks)) - assert all(jdk.startswith("zulu:") for jdk in zulu_jdks) diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..ae21b19 --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,39 @@ +# This file is part of cjdk. +# Copyright 2022-25 Board of Regents of the University of Wisconsin System +# SPDX-License-Identifier: MIT + +from cjdk import _api + + +def test_list_vendors(): + vendors = _api.list_vendors() + assert vendors is not None + assert "adoptium" in vendors + assert "corretto" in vendors + assert "graalvm" in vendors + assert "ibm-semeru-openj9" in vendors + assert "java-oracle" in vendors + assert "liberica" in vendors + assert "temurin" in vendors + assert "zulu" in vendors + + +def test_list_jdks(): + jdks = _api.list_jdks(cached_only=False) + assert jdks is not None + assert "adoptium:1.21.0.4" in jdks + assert "corretto:21.0.4.7.1" in jdks + assert "graalvm-community:21.0.2" in jdks + assert "graalvm-java21:21.0.2" in jdks + assert "liberica:22.0.2" in jdks + assert "temurin:1.21.0.4" in jdks + assert "zulu:8.0.362" in jdks + + cached_jdks = _api.list_jdks() + assert cached_jdks is not None + assert len(cached_jdks) < len(jdks) + + zulu_jdks = _api.list_jdks(vendor="zulu", cached_only=False) + assert zulu_jdks is not None + assert len(set(zulu_jdks)) + assert all(jdk.startswith("zulu:") for jdk in zulu_jdks)