|
| 1 | +# Copyright 2023 The StackStorm Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +from pants.core.goals.tailor import ( |
| 19 | + AllOwnedSources, |
| 20 | + PutativeTarget, |
| 21 | + PutativeTargets, |
| 22 | +) |
| 23 | +from pants.testutil.rule_runner import QueryRule, RuleRunner |
| 24 | + |
| 25 | +from .tailor import ( |
| 26 | + PutativePackMetadataTargetsRequest, |
| 27 | + rules as pack_metadata_rules, |
| 28 | +) |
| 29 | +from .target_types import PackMetadata, PackMetadataInGitSubmodule |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture |
| 33 | +def rule_runner() -> RuleRunner: |
| 34 | + return RuleRunner( |
| 35 | + rules=[ |
| 36 | + *pack_metadata_rules(), |
| 37 | + QueryRule( |
| 38 | + PutativeTargets, (PutativePackMetadataTargetsRequest, AllOwnedSources) |
| 39 | + ), |
| 40 | + ], |
| 41 | + target_types=[PackMetadata, PackMetadataInGitSubmodule], |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +def test_find_putative_targets(rule_runner: RuleRunner) -> None: |
| 46 | + rule_runner.write_files( |
| 47 | + { |
| 48 | + "packs/already_owned/pack.yaml": "---\nname: already_owned\n", |
| 49 | + "packs/already_owned/actions/action.yaml": "---\nname: action\n", |
| 50 | + "packs/foo/pack.yaml": "---\nname: foo\n", |
| 51 | + "packs/foo/actions/action.yaml": "---\nname: action\n", |
| 52 | + "packs/bar/pack.yaml": "---\nname: bar\n", |
| 53 | + "packs/bar/sensors/sensor.yaml": "---\nname: sensor\n", |
| 54 | + "other/deep/baz/pack.yaml": "---\nname: baz\n", |
| 55 | + } |
| 56 | + ) |
| 57 | + pts = rule_runner.request( |
| 58 | + PutativeTargets, |
| 59 | + [ |
| 60 | + PutativePackMetadataTargetsRequest( |
| 61 | + ( |
| 62 | + "packs", |
| 63 | + "packs/already_owned", |
| 64 | + "packs/already_owned/actions", |
| 65 | + "packs/foo", |
| 66 | + "packs/foo/actions", |
| 67 | + "packs/bar", |
| 68 | + "packs/bar/sensors", |
| 69 | + "other/deep/baz", |
| 70 | + ) |
| 71 | + ), |
| 72 | + AllOwnedSources( |
| 73 | + [ |
| 74 | + "packs/already_owned/pack.yaml", |
| 75 | + "packs/already_owned/actions/action.yaml", |
| 76 | + ] |
| 77 | + ), |
| 78 | + ], |
| 79 | + ) |
| 80 | + assert ( |
| 81 | + PutativeTargets( |
| 82 | + [ |
| 83 | + PutativeTarget.for_target_type( |
| 84 | + PackMetadata, |
| 85 | + path="packs/foo", |
| 86 | + name="metadata", |
| 87 | + triggering_sources=["pack.yaml"], |
| 88 | + kwargs={"name": "metadata"}, |
| 89 | + ), |
| 90 | + PutativeTarget.for_target_type( |
| 91 | + PackMetadata, |
| 92 | + path="packs/bar", |
| 93 | + name="metadata", |
| 94 | + triggering_sources=["pack.yaml"], |
| 95 | + kwargs={"name": "metadata"}, |
| 96 | + ), |
| 97 | + PutativeTarget.for_target_type( |
| 98 | + PackMetadata, |
| 99 | + path="other/deep/baz", |
| 100 | + name="metadata", |
| 101 | + triggering_sources=["pack.yaml"], |
| 102 | + kwargs={"name": "metadata"}, |
| 103 | + ), |
| 104 | + ] |
| 105 | + ) |
| 106 | + == pts |
| 107 | + ) |
0 commit comments