gtristan commented on code in PR #1994: URL: https://github.com/apache/buildstream/pull/1994#discussion_r2072621203
########## tests/frontend/show_artifact_cas_digest.py: ########## @@ -0,0 +1,291 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Pylint doesn't play well with fixtures and dependency injection from pytest +# pylint: disable=redefined-outer-name + +import os +import shutil + +import pytest + +from buildstream._testing import cli # pylint: disable=unused-import +from buildstream.exceptions import ErrorDomain + +from tests.testutils import ( + create_artifact_share, + assert_shared, + assert_not_shared, +) + + +DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "show_artifact_cas_digest_project") + + +# This tests that a target that hasn't been built locally +# and that isn't cached remotely has not artifact CAS +# digest. +# +# The test is performed without a remote cache. +# [email protected](DATA_DIR) [email protected]( + "target", + [ + ("import-basic-files.bst"), + ("import-executable-files.bst"), + ("import-symlinks.bst"), + ], +) +def test_show_artifact_cas_digest_uncached_no_remote(cli, tmpdir, datafiles, target): + project = str(datafiles) + expected_no_digest = "" + + # Check the target has not been built locally and is not existing in the remote cache + assert cli.get_element_state(project, target) != "cached" # May be "buildable" or "waiting" but shouldn't be "cached" + + # Check the target has no artifact digest + result = cli.run(project=project, silent=True, args=["show", "--format", "%{name},%{artifact-cas-digest}", target]) + result.assert_success() + + received_digest = result.output.splitlines()[0] + assert received_digest == "{target},{digest}".format(target=target, digest=expected_no_digest) + + +# This tests that a target that hasn't been built locally +# and that isn't cached remotely has no artifact CAS +# digest. +# +# The test is performed with a remote cache. +# [email protected](DATA_DIR) [email protected]( + "target", + [ + ("import-basic-files.bst"), + ("import-executable-files.bst"), + ("import-symlinks.bst"), + ], +) +def test_show_artifact_cas_digest_uncached(cli, tmpdir, datafiles, target): + project = str(datafiles) + expected_no_digest = "" + + # Configure a local cache + local_cache = os.path.join(str(tmpdir), "cache") + cli.configure({"cachedir": local_cache}) + + with create_artifact_share(os.path.join(str(tmpdir), "artifactshare")) as share: Review Comment: For this test, we are just testing something that is not cached locally and not cached remotely. * We don't need an artifact share to simulate presence in a remote * We don't need to test this on multiple, differing kinds of elements * The different kinds of elements are interesting to test only in a single test which checks all of the various digest values -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
