Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfpm: Improve clarity of test names and where to packager fields #21310

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/python/pants/backend/nfpm/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class NfpmPackageTarget(Target):
pass


# NB: The <packager>_FIELDS constants are used as Nfpm<packager>PackageFieldSet.required_fields,
# which is used when generating the nfpm config file. The field_set.nfpm_config method loops
# over required_fields, using the nfpm_alias class var on each field to construct the cpnfig.
# Some fields, like 'scripts' cannot rely on the nfpm_alias-based logic, however,
# so they are NOT included in the <packager>_FIELDS constants and are handled separately.
cognifloyd marked this conversation as resolved.
Show resolved Hide resolved


APK_FIELDS = (
NfpmPackageNameField,
NfpmArchField,
Expand All @@ -137,6 +144,7 @@ class NfpmApkPackage(NfpmPackageTarget):
core_fields = (
*COMMON_NFPM_PACKAGE_FIELDS,
*APK_FIELDS,
# 'scripts' should not be in APK_FIELDS (see note above)
NfpmApkScriptsField,
)
help = help_text(
Expand Down Expand Up @@ -178,6 +186,7 @@ class NfpmArchlinuxPackage(NfpmPackageTarget):
core_fields = (
*COMMON_NFPM_PACKAGE_FIELDS,
*ARCHLINUX_FIELDS,
# 'scripts' should not be in ARCHLINUX_FIELDS (see note above)
NfpmArchlinuxScriptsField,
)
help = help_text(
Expand Down Expand Up @@ -231,6 +240,7 @@ class NfpmDebPackage(NfpmPackageTarget):
core_fields = (
*COMMON_NFPM_PACKAGE_FIELDS,
*DEB_FIELDS,
# 'scripts' should not be in DEB_FIELDS (see note above)
NfpmDebScriptsField,
)
help = help_text(
Expand Down Expand Up @@ -281,6 +291,7 @@ class NfpmRpmPackage(NfpmPackageTarget):
core_fields = (
*COMMON_NFPM_PACKAGE_FIELDS,
*RPM_FIELDS,
# 'scripts' and 'ghost_contents' should not be in RPM_FIELDS (see note above)
NfpmRpmScriptsField,
NfpmRpmGhostContents,
)
Expand Down
119 changes: 92 additions & 27 deletions src/python/pants/backend/nfpm/util_rules/generate_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,75 @@ def get_digest(rule_runner: RuleRunner, source_files: dict[str, str]) -> Digest:
),
(
# no dependencies
("apk", NfpmApkPackageFieldSet, [], {}, [], {}, None),
("archlinux", NfpmArchlinuxPackageFieldSet, [], {}, [], {}, None),
("deb", NfpmDebPackageFieldSet, [], {}, [], {}, None),
("rpm", NfpmRpmPackageFieldSet, [], {}, [], {}, None),
("rpm", NfpmRpmPackageFieldSet, [], {}, [], {"ghost_contents": ["/var/log/pkg.log"]}, None),
pytest.param("apk", NfpmApkPackageFieldSet, [], {}, [], {}, None, id="apk-no-deps"),
pytest.param(
"archlinux", NfpmArchlinuxPackageFieldSet, [], {}, [], {}, None, id="archlinux-no-deps"
),
pytest.param("deb", NfpmDebPackageFieldSet, [], {}, [], {}, None, id="deb-no-deps"),
pytest.param("rpm", NfpmRpmPackageFieldSet, [], {}, [], {}, None, id="rpm-no-deps"),
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
[],
{},
[],
{"ghost_contents": ["/var/log/pkg.log"]},
None,
id="rpm-no-deps-with-ghost",
),
# no dependencies (extra file does not cause errors)
("apk", NfpmApkPackageFieldSet, [], {}, ["contents/extra-file.txt"], {}, None),
("archlinux", NfpmArchlinuxPackageFieldSet, [], {}, ["contents/extra-file.txt"], {}, None),
("deb", NfpmDebPackageFieldSet, [], {}, ["contents/extra-file.txt"], {}, None),
("rpm", NfpmRpmPackageFieldSet, [], {}, ["contents/extra-file.txt"], {}, None),
(
pytest.param(
"apk",
NfpmApkPackageFieldSet,
[],
{},
["contents/extra-file.txt"],
{},
None,
id="apk-no-deps-with-extra-file",
),
pytest.param(
"archlinux",
NfpmArchlinuxPackageFieldSet,
[],
{},
["contents/extra-file.txt"],
{},
None,
id="archlinux-no-deps-with-extra-file",
),
pytest.param(
"deb",
NfpmDebPackageFieldSet,
[],
{},
["contents/extra-file.txt"],
{},
None,
id="deb-no-deps-with-extra-file",
),
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
[],
{},
["contents/extra-file.txt"],
{},
None,
id="rpm-no-deps-with-extra-file",
),
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
[],
{},
["contents/extra-file.txt"],
{"ghost_contents": ["/var/log/pkg.log"]},
None,
id="rpm-no-deps-with-extra-file-and-ghost",
),
# with dependencies
(
pytest.param(
"apk",
NfpmApkPackageFieldSet,
[
Expand All @@ -123,8 +171,9 @@ def get_digest(rule_runner: RuleRunner, source_files: dict[str, str]) -> Digest:
],
{},
None,
id="apk-with-deps",
),
(
pytest.param(
"archlinux",
NfpmArchlinuxPackageFieldSet,
[
Expand All @@ -144,8 +193,9 @@ def get_digest(rule_runner: RuleRunner, source_files: dict[str, str]) -> Digest:
],
{},
None,
id="archlinux-with-deps",
),
(
pytest.param(
"deb",
NfpmDebPackageFieldSet,
[
Expand All @@ -165,8 +215,9 @@ def get_digest(rule_runner: RuleRunner, source_files: dict[str, str]) -> Digest:
],
{},
None,
id="deb-with-deps",
),
(
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
[
Expand All @@ -186,8 +237,9 @@ def get_digest(rule_runner: RuleRunner, source_files: dict[str, str]) -> Digest:
],
{},
None,
id="rpm-with-deps",
),
(
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
[
Expand All @@ -207,117 +259,130 @@ def get_digest(rule_runner: RuleRunner, source_files: dict[str, str]) -> Digest:
],
{"ghost_contents": ["/var/log/pkg.log"]},
None,
id="rpm-with-deps-and-ghost",
),
# with malformed dependency
(
pytest.param(
"apk",
NfpmApkPackageFieldSet,
["contents:malformed"],
{},
[],
{},
pytest.raises(ExecutionError),
id="apk-with-malformed-dep",
),
(
pytest.param(
"archlinux",
NfpmArchlinuxPackageFieldSet,
["contents:malformed"],
{},
[],
{},
pytest.raises(ExecutionError),
id="archlinux-with-malformed-dep",
),
(
pytest.param(
"deb",
NfpmDebPackageFieldSet,
["contents:malformed"],
{},
[],
{},
pytest.raises(ExecutionError),
id="deb-with-malformed-dep",
),
(
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
["contents:malformed"],
{},
[],
{},
pytest.raises(ExecutionError),
id="rpm-with-malformed-dep",
),
# with dependency file missing from sandbox
(
pytest.param(
"apk",
NfpmApkPackageFieldSet,
["contents:files", "contents:file"],
{},
[],
{},
pytest.raises(ExecutionError),
id="apk-missing-dep-file",
),
(
pytest.param(
"archlinux",
NfpmArchlinuxPackageFieldSet,
["contents:files", "contents:file"],
{},
[],
{},
pytest.raises(ExecutionError),
id="archlinux-missing-dep-file",
),
(
pytest.param(
"deb",
NfpmDebPackageFieldSet,
["contents:files", "contents:file"],
{},
[],
{},
pytest.raises(ExecutionError),
id="deb-missing-dep-file",
),
(
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
["contents:files", "contents:file"],
{},
[],
{},
pytest.raises(ExecutionError),
id="rpm-missing-dep-file",
),
# with script file missing from sandbox
(
pytest.param(
"apk",
NfpmApkPackageFieldSet,
[],
{"postinstall": "scripts/postinstall.sh", "postupgrade": "scripts/apk-postupgrade.sh"},
[],
{},
pytest.raises(ExecutionError),
id="apk-missing-script-file",
),
(
pytest.param(
"archlinux",
NfpmArchlinuxPackageFieldSet,
[],
{"postinstall": "scripts/postinstall.sh", "postupgrade": "scripts/arch-postupgrade.sh"},
[],
{},
pytest.raises(ExecutionError),
id="archlinux-missing-script-file",
),
(
pytest.param(
"deb",
NfpmDebPackageFieldSet,
[],
{"postinstall": "scripts/postinstall.sh", "config": "scripts/deb-config.sh"},
[],
{},
pytest.raises(ExecutionError),
id="deb-missing-script-file",
),
(
pytest.param(
"rpm",
NfpmRpmPackageFieldSet,
[],
{"postinstall": "scripts/postinstall.sh", "verify": "scripts/rpm-verify.sh"},
[],
{},
pytest.raises(ExecutionError),
id="rpm-missing-script-file",
),
),
)
Expand Down
Loading
Loading