Add tests for pkg_deb output file names (#444)

* add a test to check the deb .changes file has the right name
This commit is contained in:
aiuto 2021-11-04 15:56:14 -04:00 committed by GitHub
parent 036362cd91
commit d0997d0d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 95 additions and 24 deletions

View File

@ -15,16 +15,17 @@
# Tests for pkg_deb specific behavior
load("@rules_python//python:defs.bzl", "py_test")
load(":deb_tests.bzl", "package_naming_test")
load("//pkg:mappings.bzl", "pkg_mklink")
load("//pkg:pkg.bzl", "pkg_deb", "pkg_tar")
load("//tests:my_package_name.bzl", "my_package_naming")
load("@rules_python//python:defs.bzl", "py_test")
genrule(
name = "generate_files",
outs = [
"etc/nsswitch.conf",
"usr/titi",
"usr/fizzbuzz",
],
cmd = "for i in $(OUTS); do echo 1 >$$i; done",
)
@ -45,28 +46,28 @@ pkg_tar(
srcs = [
":etc/nsswitch.conf",
":java_link",
":usr/titi",
":usr/fizzbuzz",
],
extension = "tar.gz",
mode = "0644",
modes = {"usr/titi": "0755"},
modes = {"usr/fizzbuzz": "0755"},
owner = "42.24",
ownername = "titi.tata",
ownernames = {"etc/nsswitch.conf": "tata.titi"},
ownername = "fizzbuzz.foobar",
ownernames = {"etc/nsswitch.conf": "foobar.fizzbuzz"},
owners = {"etc/nsswitch.conf": "24.42"},
package_dir = "/",
strip_prefix = ".",
)
pkg_deb(
name = "test-deb",
name = "test_deb",
breaks = ["oldbrokenpkg"],
built_using = "some_test_data (0.1.2)",
conffiles = [
"/etc/nsswitch.conf",
"/etc/other",
],
config = "//tests:testdata/config",
config = "config",
data = ":tar_input",
depends = [
"dep1",
@ -75,12 +76,12 @@ pkg_deb(
description = "toto ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é",
distribution = "trusty",
maintainer = "soméone@somewhere.com",
package = "titi",
preinst = "//tests:testdata/deb_preinst",
package = "fizzbuzz",
preinst = "deb_preinst",
provides = ["hello"],
replaces = ["oldpkg"],
templates = "//tests:testdata/templates",
triggers = "//tests:testdata/deb_triggers",
templates = "templates",
triggers = "deb_triggers",
urgency = "low",
version = "test",
)
@ -93,7 +94,7 @@ py_test(
],
data = [
# The target includes both the .deb and .changes files in DefaultInfo
":test-deb",
":test_deb",
],
python_version = "PY3",
deps = [
@ -101,3 +102,9 @@ py_test(
"@bazel_tools//tools/python/runfiles",
],
)
package_naming_test(
name = "naming_test",
target_under_test = ":test_deb",
expected_name = "fizzbuzz_test_all.deb",
)

1
tests/deb/config Normal file
View File

@ -0,0 +1 @@
# test config file

3
tests/deb/deb_preinst Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
# tete ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é
echo fnord

52
tests/deb/deb_tests.bzl Normal file
View File

@ -0,0 +1,52 @@
# Copyright 2021 The Bazel Authors. All rights reserved.
#
# 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.
"""Helpers for pkg_deb tests."""
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
def _package_naming_test_impl(ctx):
env = analysistest.begin(ctx)
target_under_test = analysistest.target_under_test(env)
ogi = target_under_test[OutputGroupInfo]
deb_path = ogi.deb.to_list()[0].path
# Test that the .changes file is computed correctly
changes_path = ogi.changes.to_list()[0].path
expected_changes_path = deb_path[0:-3] + "changes"
asserts.equals(
env,
changes_path,
expected_changes_path,
"Changes file does not have the correct name",
)
# Is the generated file name what we expect
if ctx.attr.expected_name:
asserts.equals(
env,
deb_path.split("/")[-1], # basename(path)
ctx.attr.expected_name,
"Deb package file name is not correct",
)
return analysistest.end(env)
package_naming_test = analysistest.make(
_package_naming_test_impl,
attrs = {
"expected_name": attr.string(),
},
)

2
tests/deb/deb_triggers Normal file
View File

@ -0,0 +1,2 @@
# tutu ®, Й, ק ,م, ๗, あ, 叶, 葉, 말, ü and é
some-trigger

View File

@ -63,7 +63,7 @@ class PkgDebTest(unittest.TestCase):
super(PkgDebTest, self).setUp()
self.runfiles = runfiles.Create()
# Note: Rlocation requires forward slashes. os.path.join() will not work.
self.deb_path = self.runfiles.Rlocation('rules_pkg/tests/deb/titi_test_all.deb')
self.deb_path = self.runfiles.Rlocation('rules_pkg/tests/deb/fizzbuzz_test_all.deb')
self.deb_file = DebInspect(self.deb_path)
def assert_control_content(self, expected, match_order=False):
@ -135,25 +135,25 @@ class PkgDebTest(unittest.TestCase):
expected = [
{'name': '.', 'isdir': True},
{'name': './etc', 'isdir': True,
'uid': 24, 'gid': 42, 'uname': 'tata', 'gname': 'titi'},
'uid': 24, 'gid': 42, 'uname': 'foobar', 'gname': 'fizzbuzz'},
{'name': './etc/nsswitch.conf',
'mode': 0o644,
'uid': 24, 'gid': 42, 'uname': 'tata', 'gname': 'titi'
'uid': 24, 'gid': 42, 'uname': 'foobar', 'gname': 'fizzbuzz'
},
{'name': './usr', 'isdir': True,
'uid': 42, 'gid': 24, 'uname': 'titi', 'gname': 'tata'},
'uid': 42, 'gid': 24, 'uname': 'fizzbuzz', 'gname': 'foobar'},
{'name': './usr/bin', 'isdir': True},
{'name': './usr/bin/java', 'linkname': '/path/to/bin/java'},
{'name': './usr/titi',
{'name': './usr/fizzbuzz',
'mode': 0o755,
'uid': 42, 'gid': 24, 'uname': 'titi', 'gname': 'tata'},
'uid': 42, 'gid': 24, 'uname': 'fizzbuzz', 'gname': 'foobar'},
]
self.assert_data_content(expected)
def test_description(self):
control = self.deb_file.get_deb_ctl_file('control')
fields = [
'Package: titi',
'Package: fizzbuzz',
'Depends: dep1, dep2',
'Built-Using: some_test_data',
'Replaces: oldpkg',
@ -202,7 +202,7 @@ class PkgDebTest(unittest.TestCase):
def test_templates(self):
templates = self.deb_file.get_deb_ctl_file('templates')
for field in ('Template: titi/test', 'Type: string'):
for field in ('Template: deb/test', 'Type: string'):
if templates.find(field) < 0:
self.fail('Missing template field: <%s> in <%s>' % (field, templates))
@ -215,7 +215,7 @@ class PkgDebTest(unittest.TestCase):
def test_changes(self):
changes_path = self.runfiles.Rlocation(
'rules_pkg/tests/deb/titi_test_all.changes')
'rules_pkg/tests/deb/fizzbuzz_test_all.changes')
with open(changes_path, 'r', encoding='utf-8') as f:
content = f.read()
for field in (

6
tests/deb/templates Normal file
View File

@ -0,0 +1,6 @@
Template: deb/test
Type: string
Default:
Description: test question
test question to check that templates are included into
debian directory

View File

@ -1,6 +1,6 @@
Template: titi/test
Template: deb/test
Type: string
Default:
Description: test question
test question to check that templates are included into
debian directory
debian directory