Skip to content

Commit a39ba3f

Browse files
authored
test: add an integration test for xz decompression (#243)
* refactor: explicitly use gz compression for e2e fixture tars * test: add an integration test for xz decompression
1 parent a4fa63b commit a39ba3f

File tree

19 files changed

+284
-78
lines changed

19 files changed

+284
-78
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ bazel_dep(name = "platforms", version = "0.0.11")
1212
bazel_dep(name = "rules_multitool", version = "0.15.0")
1313
bazel_dep(name = "rules_nodejs", version = "6.3.3")
1414
bazel_dep(name = "rules_pkg", version = "1.0.1")
15+
bazel_dep(name = "rules_xz", version = "1.0.1")
1516
bazel_dep(name = "toolchains_llvm", version = "1.2.0")
1617
bazel_dep(name = "xz", version = "5.4.5.bcr.5")
1718

babel.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["@babel/preset-env"]
2+
"presets": ["@babel/preset-env"],
3+
"plugins": ["babel-plugin-transform-import-meta"]
34
}

bazel/jest/defs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def jest_test(name, **kwargs):
3131
data = data + [
3232
"babel.config.json",
3333
"//:node_modules/@babel/preset-env",
34+
"//:node_modules/babel-plugin-transform-import-meta",
3435
"//:package_json",
3536
],
3637
node_modules = "//:node_modules",

dist/cli/index.js

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/cli/e2e.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mock_attestation() {
6363
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"
6464
FIXTURE="${TEST_TMPDIR}/$(basename "${FIXTURE}")"
6565
TEMPLATES_DIR="${FIXTURE}/.bcr"
66-
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar"
66+
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar.gz"
6767

6868
swap_source_url "${TEMPLATES_DIR}/source.template.json" "file://$(realpath "${RELEASE_ARCHIVE}")"
6969

@@ -105,7 +105,7 @@ mock_attestation() {
105105
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"
106106
FIXTURE="${TEST_TMPDIR}/$(basename "${FIXTURE}")"
107107
TEMPLATES_DIR="${FIXTURE}/.bcr"
108-
RELEASE_ARCHIVE="e2e/fixtures/attestations-attestations-1.0.0.tar"
108+
RELEASE_ARCHIVE="e2e/fixtures/attestations-attestations-1.0.0.tar.gz"
109109

110110
SOURCE_ATTESTATION=$(mock_attestation "source.json.intoto.jsonl")
111111
MODULE_ATTESTATION=$(mock_attestation "MODULE.bazel.intoto.jsonl")
@@ -130,7 +130,7 @@ mock_attestation() {
130130
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"
131131
FIXTURE="${TEST_TMPDIR}/$(basename "${FIXTURE}")"
132132
TEMPLATES_DIR="${FIXTURE}/.bcr"
133-
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar"
133+
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar.gz"
134134

135135
swap_source_url "${TEMPLATES_DIR}/source.template.json" "file://$(realpath "${RELEASE_ARCHIVE}")"
136136

@@ -146,7 +146,7 @@ mock_attestation() {
146146
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"
147147
FIXTURE="${TEST_TMPDIR}/$(basename "${FIXTURE}")"
148148
TEMPLATES_DIR="${FIXTURE}/.bcr"
149-
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar"
149+
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar.gz"
150150

151151
swap_source_url "${TEMPLATES_DIR}/source.template.json" "file://$(realpath "${RELEASE_ARCHIVE}")"
152152

e2e/fixtures/BUILD.bazel

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,75 @@ load(":fixture.bzl", "fixture_archive")
33

44
fixture_archive(
55
name = "attestations",
6-
archive = "tar",
6+
archive = "tar.gz",
77
prefix = "attestations-1.0.0",
88
)
99

1010
fixture_archive(
1111
name = "empty-prefix",
12-
archive = "tar",
12+
archive = "tar.gz",
1313
prefix = None,
1414
)
1515

1616
fixture_archive(
1717
name = "fixed-releaser",
18-
archive = "tar",
18+
archive = "tar.gz",
1919
prefix = "fixed-releaser-1.0.0",
2020
)
2121

2222
fixture_archive(
2323
name = "multi-module",
24-
archive = "tar",
24+
archive = "tar.gz",
2525
prefix = "multi-module-1.0.0",
2626
)
2727

2828
fixture_archive(
2929
name = "multi-module_invalid_prefix",
30-
archive = "tar",
30+
archive = "tar.gz",
3131
fixture = "multi-module",
3232
prefix = "invalid-prefix",
3333
)
3434

3535
fixture_archive(
3636
name = "no-prefix",
37-
archive = "tar",
37+
archive = "tar.gz",
3838
prefix = None,
3939
)
4040

4141
fixture_archive(
4242
name = "tarball",
43-
archive = "tar",
43+
archive = "tar.gz",
4444
prefix = "tarball-1.0.0",
4545
)
4646

47+
fixture_archive(
48+
name = "tarball-xz",
49+
archive = "tar.xz",
50+
prefix = "tarball-xz-1.0.0",
51+
)
52+
4753
fixture_archive(
4854
name = "unversioned",
49-
archive = "tar",
55+
archive = "tar.gz",
5056
prefix = "unversioned-1.0.0",
5157
)
5258

5359
fixture_archive(
5460
name = "versioned",
55-
archive = "tar",
61+
archive = "tar.gz",
5662
prefix = "versioned-1.0.0",
5763
)
5864

5965
fixture_archive(
6066
name = "versioned_invalid_prefix",
61-
archive = "tar",
67+
archive = "tar.gz",
6268
fixture = "versioned",
6369
prefix = "invalid-prefix",
6470
)
6571

6672
fixture_archive(
6773
name = "zero-versioned",
68-
archive = "tar",
74+
archive = "tar.gz",
6975
prefix = "zero-versioned-1.0.0",
7076
)
7177

e2e/fixtures/fixture.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
44
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
55
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
6+
load("@rules_xz//xz/compress:defs.bzl", "xz_compress")
67

78
def fixture_archive(name, archive, prefix, fixture = None):
89
"""Create a release archive for a module fixture
@@ -31,11 +32,26 @@ def fixture_archive(name, archive, prefix, fixture = None):
3132
out = "{}-{}.zip".format(fixture, "" if prefix == None else prefix),
3233
visibility = ["//e2e:__subpackages__"],
3334
)
34-
elif archive == "tar":
35+
elif archive == "tar.gz":
3536
pkg_tar(
3637
name = name,
3738
srcs = [":{}_files".format(name)],
3839
package_dir = prefix,
40+
out = "{}-{}.tar.gz".format(fixture, "" if prefix == None else prefix),
41+
extension = "tar.gz",
42+
visibility = ["//e2e:__subpackages__"],
43+
)
44+
elif archive == "tar.xz":
45+
pkg_tar(
46+
name = "{}_archive".format(name),
47+
srcs = [":{}_files".format(name)],
48+
package_dir = prefix,
3949
out = "{}-{}.tar".format(fixture, "" if prefix == None else prefix),
50+
extension = "tar",
51+
)
52+
53+
xz_compress(
54+
name = name,
55+
src = "{}_archive".format(name),
4056
visibility = ["//e2e:__subpackages__"],
4157
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"homepage": "https://github.com/testorg/tarball-xz",
3+
"maintainers": [
4+
{
5+
"name": "Foo McBar",
6+
"email": "[email protected]",
7+
"github": "foobar"
8+
}
9+
],
10+
"repository": ["github:testorg/tarball-xz"],
11+
"versions": [],
12+
"yanked_versions": {}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bcr_test_module:
2+
module_path: "e2e/bzlmod"
3+
matrix:
4+
platform: ["debian10", "macos", "ubuntu2004", "windows"]
5+
bazel: [6.x, 7.x]
6+
tasks:
7+
run_tests:
8+
name: "Run test module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
test_targets:
12+
- "//..."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "",
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.xz"
5+
}

0 commit comments

Comments
 (0)