Skip to content

Commit a2f076f

Browse files
committed
tests/integration: Add tests for digest-environment
1 parent 9588425 commit a2f076f

File tree

6 files changed

+229
-0
lines changed

6 files changed

+229
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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 shutil
20+
21+
import pytest
22+
23+
from buildstream._testing import cli_integration as cli # pylint: disable=unused-import
24+
from buildstream._testing._utils.site import HAVE_SANDBOX
25+
26+
from tests.testutils import create_artifact_share
27+
28+
pytestmark = pytest.mark.integration
29+
30+
31+
DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "project")
32+
33+
34+
# Test that the digest environment variable is set correctly during a build
35+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
36+
@pytest.mark.datafiles(DATA_DIR)
37+
def test_build_checkout_base(cli, datafiles):
38+
project = str(datafiles)
39+
element_name = "digest-environment/base.bst"
40+
41+
result = cli.run(project=project, args=["build", element_name])
42+
assert result.exit_code == 0
43+
44+
result = cli.run(project=project, args=["artifact", "checkout", element_name])
45+
assert result.exit_code == 0
46+
47+
48+
# Test that the digest environment variable is not affected by unrelated build dependencies
49+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
50+
@pytest.mark.datafiles(DATA_DIR)
51+
def test_build_base_plus_extra_dep(cli, datafiles):
52+
project = str(datafiles)
53+
element_name = "digest-environment/base-plus-extra-dep.bst"
54+
55+
result = cli.run(project=project, args=["build", element_name])
56+
assert result.exit_code == 0
57+
58+
59+
# Test that multiple dependencies can be merged into a single digest environment variable
60+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
61+
@pytest.mark.datafiles(DATA_DIR)
62+
def test_build_merge(cli, datafiles):
63+
project = str(datafiles)
64+
element_name = "digest-environment/merge.bst"
65+
66+
result = cli.run(project=project, args=["build", element_name])
67+
assert result.exit_code == 0
68+
69+
70+
# Test that multiple digest environment variables can be configured in a single element
71+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
72+
@pytest.mark.datafiles(DATA_DIR)
73+
def test_build_two(cli, datafiles):
74+
project = str(datafiles)
75+
element_name = "digest-environment/two.bst"
76+
77+
result = cli.run(project=project, args=["build", element_name])
78+
assert result.exit_code == 0
79+
80+
81+
# Test that the digest environment variable is also set in a build shell
82+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
83+
@pytest.mark.datafiles(DATA_DIR)
84+
def test_build_shell(cli, datafiles):
85+
project = str(datafiles)
86+
element_name = "digest-environment/base.bst"
87+
88+
# Ensure artifacts of build dependencies are available for build shell
89+
result = cli.run(project=project, args=["build", "--deps", "build", element_name])
90+
assert result.exit_code == 0
91+
92+
result = cli.run(project=project, args=["shell", "--build", element_name, "--", "sh", "-c", "echo $BASE_DIGEST"])
93+
assert result.exit_code == 0
94+
assert result.output.strip() == "63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
95+
96+
97+
# Test that the digest environment variable is also set in a build shell staged from a buildtree
98+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
99+
@pytest.mark.datafiles(DATA_DIR)
100+
def test_build_shell_buildtree(cli, datafiles):
101+
project = str(datafiles)
102+
element_name = "digest-environment/base-buildtree.bst"
103+
104+
# Generate buildtree
105+
result = cli.run(project=project, args=["--cache-buildtrees", "always", "build", element_name])
106+
assert result.exit_code == 0
107+
108+
result = cli.run(
109+
project=project,
110+
args=["shell", "--build", "--use-buildtree", element_name, "--", "sh", "-c", "echo $BASE_DIGEST"],
111+
)
112+
assert result.exit_code == 0
113+
assert result.output.strip() == "63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
114+
115+
116+
# Test that buildtree push works for elements with a digest environment variable
117+
@pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
118+
@pytest.mark.datafiles(DATA_DIR)
119+
def test_pushed_buildtree(cli, tmpdir, datafiles):
120+
project = str(datafiles)
121+
element_name = "digest-environment/merge.bst"
122+
123+
with create_artifact_share(os.path.join(str(tmpdir), "share")) as share:
124+
cli.configure(
125+
{
126+
"artifacts": {"servers": [{"url": share.repo, "push": True}]},
127+
"cachedir": str(tmpdir),
128+
"cache": {"cache-buildtrees": "always"},
129+
}
130+
)
131+
132+
# Generate buildtree
133+
result = cli.run(project=project, args=["build", element_name])
134+
assert result.exit_code == 0
135+
136+
assert cli.get_element_state(project, element_name) == "cached"
137+
assert share.get_artifact(cli.get_artifact_name(project, "test", element_name))
138+
139+
# Clear the local cache to make sure everything can and will be pulled from the remote
140+
shutil.rmtree(os.path.join(str(tmpdir), "cas"))
141+
shutil.rmtree(os.path.join(str(tmpdir), "artifacts"))
142+
143+
result = cli.run(
144+
project=project,
145+
args=[
146+
"--pull-buildtrees",
147+
"shell",
148+
"--build",
149+
"--use-buildtree",
150+
element_name,
151+
"--",
152+
"sh",
153+
"-c",
154+
"echo $MERGED_DIGEST",
155+
],
156+
)
157+
assert result.exit_code == 0
158+
assert result.output.strip() == "469369597f4faa56c4b8338d6a948c8c1d4f29e6ea8f4d4d261cac4182bcef48/1389"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: manual
2+
3+
depends:
4+
- filename: base.bst
5+
type: build
6+
config:
7+
digest-environment: BASE_DIGEST
8+
9+
config:
10+
build-commands:
11+
- env
12+
- test "$BASE_DIGEST" = "63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
kind: manual
2+
3+
depends:
4+
- filename: base.bst
5+
type: build
6+
config:
7+
digest-environment: BASE_DIGEST
8+
- filename: manual/import-file.bst
9+
type: build
10+
11+
config:
12+
build-commands:
13+
- env
14+
- test "$BASE_DIGEST" = "63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: manual
2+
3+
depends:
4+
- filename: base.bst
5+
type: build
6+
config:
7+
digest-environment: BASE_DIGEST
8+
9+
config:
10+
build-commands:
11+
- env
12+
- test "$BASE_DIGEST" = "63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
kind: manual
2+
3+
depends:
4+
- filename: base.bst
5+
type: build
6+
config:
7+
digest-environment: MERGED_DIGEST
8+
- filename: manual/import-file.bst
9+
type: build
10+
config:
11+
digest-environment: MERGED_DIGEST
12+
13+
config:
14+
build-commands:
15+
- env
16+
- test "$MERGED_DIGEST" = "469369597f4faa56c4b8338d6a948c8c1d4f29e6ea8f4d4d261cac4182bcef48/1389"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
kind: manual
2+
3+
depends:
4+
- filename: base.bst
5+
type: build
6+
config:
7+
digest-environment: BASE_DIGEST
8+
- filename: manual/import-file.bst
9+
type: build
10+
config:
11+
digest-environment: IMPORT_DIGEST
12+
13+
config:
14+
build-commands:
15+
- env
16+
- test "$BASE_DIGEST" = "63450d93eab71f525d08378fe50960aff92b0ec8f1b0be72b2ac4b8259d09833/1227"
17+
- test "$IMPORT_DIGEST" = "eec5ed9053acb296a8e7a30ab7ee173abf4f7392b8228ba7644cd5b51a5cfdeb/162"

0 commit comments

Comments
 (0)