In the tests for <https://github.com/pantsbuild/pa...
# development
a
In the tests for https://github.com/pantsbuild/pants/pull/19346 I need to check that the BuiltPackage for a target is included on the PublishPackages. At the moment, the tests for publish just use a BuiltPackage with an EMPTY_DIGEST. Is there a straightforward way of creating a digest from some value? I can't see anywhere else in tests that we do this, so I'm guessing I'm barking up the wrong tree. In an ideal world, I'd just create a digest from, say, the address.spec_path of the docker target so that it's unique to each target. I want to be able to
Copy code
assert len(packages) == 1
assert packages[0].digest == expected_digest(docker_target)
b
There’s a
CreateDigest
request type, that can be used with
FileContents
. I don’t know if there’s a better way to create “dummy” ones for tests
a
Yeah, it just feels kinda weird running the create digest rule from the publish tests. How does one run a rule synchronously? Being able to say
dummy_digest(some_value)
seems like it's such a useful thing that I'm assuming there's a very good reason why it's not already present.
Or maybe it's not useful, because things are layered in such a way that it was never needed, and I'm violating doctrine
b
Oh, I think maybe you can just pass any arbitrary hash-shaped value (ie hex of the appropriate length: 64) to
Digest()
directly. I imagine this can’t be actually used by the engine (eg materialising it onto disk will fail), but may be appropriate for what you want?
a
Yeah, that's my thinking. I can create a function that creates a hex value from some string and gives you a digest. I just want to make sure I'm not breaking some unwritten rule, or missing a better way to test this
b
To answer your sync question: I think
rule_runner.request
is the sync-testing equivalent to
await Get()
I’ve used that and it’s not been flagged in code review by more experienced devs, so… I think it’s fine, afaik! 🤷‍♂️
a
Okies, I'll take a look at how the code comes out with rule_runner.request, and if it's stinky, I'll create a helper function to return a mock digest.
Thanks!
b
I’d guess it’ll be much stinkier than the direct
Digest()
call, and probably for not much value other than tests running slower (ie mock digest might be the way to go)
a
Okay, I'll reverse the order then, and see if anyone shouts in PR review. That's my instinct anyway, I'm just nervous that nobody else has needed this helper.
Makes me think i'm doing something dumb
b
I created one in
peek_test.py
(that particular case needed a
Snapshot
so the helper is very slightly more vigorous than just a digest) if that helps… but I’m unreliable as a source of good advice 😅
a
It does, that's reassuring, you're comparatively an expert here
b
See none, do one, teach one
f
Why not use the
make_snapshot
method on the
RuleRunner
?
👍 1
The digest is an attribute on the returned
Snapshot
.
a
Sheer ignorance. I'll have a go with that. That should solve the problems with the python publish