Debian Codegraph @

tests/sources/cargo.py

raw
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 #
14
15 # Pylint doesn't play well with fixtures and dependency injection from pytest
16 # pylint: disable=redefined-outer-name
17
18 import os
19 import pytest
20
21 from buildstream import _yaml
22 from buildstream._testing import cli # pylint: disable=unused-import
23
24 DATA_DIR = os.path.join(
25 os.path.dirname(os.path.realpath(__file__)),
26 "cargo",
27 )
28
29
30 def generate_project(project_dir):
31 project_file = os.path.join(project_dir, "project.conf")
32 _yaml.roundtrip_dump(
33 {
34 "name": "foo",
35 "min-version": "2.0",
36 "element-path": "elements",
37 "plugins": [
38 {
39 "origin": "pip",
40 "package-name": "buildstream-plugins",
41 "sources": ["cargo"],
42 }
43 ],
44 },
45 project_file,
46 )
47
48
49 @pytest.mark.datafiles(os.path.join(DATA_DIR, "minimal"))
50 def test_cargo_track_fetch_build(cli, datafiles):
51 project = str(datafiles)
52 generate_project(project)
53
54 # First track
55 result = cli.run(project=project, args=["source", "track", "base64.bst"])
56 result.assert_success()
57
58 # Now we should be able to get the source info
59 result = cli.run(project=project, args=["show", "--format", "%{name}:\n%{source-info}", "base64.bst"])
60 result.assert_success()
61 loaded = _yaml.load_data(result.output)
62 sources = loaded.get_sequence("base64.bst")
63
64 # Assert the cargo source, which is in the second position after the local source
65 source_info = sources.mapping_at(1)
66 assert source_info.get_str("kind") == "cargo"
67 assert source_info.get_str("url") == "https://static.crates.io/crates/base64/base64-0.22.1.crate"
68 assert source_info.get_str("medium") == "remote-file"
69 assert source_info.get_str("version-type") == "sha256"
70 assert source_info.get_str("version") == "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
71 assert source_info.get_str("version-guess") == "0.22.1"
72
73 # Now fetch and build
74 result = cli.run(project=project, args=["source", "fetch", "base64.bst"])
75 result.assert_success()
76 result = cli.run(project=project, args=["build", "base64.bst"])
77 result.assert_success()