Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
Tom Dyas committed May 16, 2022
1 parent 5ae0ffc commit cd8be50
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/python/pants/jvm/resolve/jvm_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import textwrap

from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
from pants.core.goals.generate_lockfiles import DEFAULT_TOOL_LOCKFILE, GenerateToolLockfileSentinel
from pants.core.util_rules import config_files, source_files
from pants.core.util_rules.external_tool import rules as external_tool_rules
from pants.engine.fs import Digest, DigestContents
Expand All @@ -20,6 +20,7 @@
from pants.jvm.target_types import JvmArtifactTarget
from pants.jvm.util_rules import rules as util_rules
from pants.testutil.rule_runner import PYTHON_BOOTSTRAP_ENV, QueryRule, RuleRunner
from pants.util.ordered_set import FrozenOrderedSet


class MockJvmTool(JvmToolBase):
Expand All @@ -36,13 +37,36 @@ class MockJvmToolLockfileSentinel(GenerateToolLockfileSentinel):
resolve_name = MockJvmTool.options_scope


class MockInternalToolLockfileSentinel(GenerateToolLockfileSentinel):
resolve_name = "mock-internal-tool"


@rule
def generate_test_tool_lockfile_request(
_: MockJvmToolLockfileSentinel, tool: MockJvmTool
) -> GenerateJvmLockfileFromTool:
return GenerateJvmLockfileFromTool.create(tool)


@rule
def generate_internal_test_tool_lockfile_request(
_: MockInternalToolLockfileSentinel,
) -> GenerateJvmLockfileFromTool:
return GenerateJvmLockfileFromTool(
artifact_inputs=FrozenOrderedSet(
{
"com.google.code.gson:gson:2.9.0",
}
),
artifact_option_name="n/a",
lockfile_option_name="n/a",
resolve_name=MockInternalToolLockfileSentinel.resolve_name,
read_lockfile_dest=DEFAULT_TOOL_LOCKFILE,
write_lockfile_dest="mock-write-lockfile.lock",
default_lockfile_resource=("pants.backend.jvm.resolve", "mock-internal-tool.lock"),
)


def test_jvm_tool_base_extracts_correct_coordinates() -> None:
rule_runner = RuleRunner(
rules=[
Expand All @@ -55,8 +79,10 @@ def test_jvm_tool_base_extracts_correct_coordinates() -> None:
*jvm_tool.rules(),
*lockfile_rules(),
generate_test_tool_lockfile_request,
generate_internal_test_tool_lockfile_request,
SubsystemRule(MockJvmTool),
QueryRule(GenerateJvmLockfile, (MockJvmToolLockfileSentinel,)),
QueryRule(GenerateJvmLockfile, (MockInternalToolLockfileSentinel,)),
QueryRule(DigestContents, (Digest,)),
],
target_types=[JvmArtifactTarget],
Expand Down Expand Up @@ -89,3 +115,9 @@ def test_jvm_tool_base_extracts_correct_coordinates() -> None:
Coordinate(group="junit", artifact="junit", version="4.13.2"),
Coordinate(group="org.hamcrest", artifact="hamcrest-core", version="1.3"),
]

# Ensure that an internal-only tool will not have a lockfile generated.
default_lockfile_result = rule_runner.request(
GenerateJvmLockfile, [MockInternalToolLockfileSentinel()]
)
assert default_lockfile_result.lockfile_dest == DEFAULT_TOOL_LOCKFILE

0 comments on commit cd8be50

Please sign in to comment.