Skip to content

Commit

Permalink
refactor: testing (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmaestro authored Oct 29, 2024
1 parent 7ba8729 commit 6ccc030
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 230 deletions.
10 changes: 10 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ load("@bullseye//:packages.bzl", "bullseye_packages")

bullseye_packages()

deb_index(
name = "bullseye_nolock",
manifest = "//examples/debian_snapshot:bullseye_nolock.yaml",
nolock = True,
)

load("@bullseye_nolock//:packages.bzl", "bullseye_nolock_packages")

bullseye_nolock_packages()

deb_index(
name = "apt_security",
manifest = "//examples/debian_snapshot_security:security.yaml",
Expand Down
12 changes: 4 additions & 8 deletions apt/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
load(":package_resolution_test.bzl", "version_depends_test")
load(":version_test.bzl", "version_compare_test", "version_parse_test", "version_sort_test")
load(":package_resolution_test.bzl", "package_resolution_tests")
load(":version_test.bzl", "version_tests")

version_compare_test(name = "version_compare_test")
package_resolution_tests()

version_parse_test(name = "version_parse_test")

version_depends_test(name = "version_depends")

version_sort_test(name = "version_sort_test")
version_tests()
106 changes: 60 additions & 46 deletions apt/tests/package_resolution_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,73 @@
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//apt/private:package_resolution.bzl", "package_resolution")

_TEST_SUITE_PREFIX = "package_resolution/"

def _parse_depends_test(ctx):
env = unittest.begin(ctx)
asserts.equals(
env,
[

parameters = {
" | ".join([
"libc6 (>= 2.2.1), default-mta",
"mail-transport-agent",
]): [
{"name": "libc6", "version": (">=", "2.2.1"), "arch": None},
[{"name": "default-mta", "version": None, "arch": None}, {"name": "mail-transport-agent", "version": None, "arch": None}],
[
{"name": "default-mta", "version": None, "arch": None},
{"name": "mail-transport-agent", "version": None, "arch": None},
],
],
package_resolution.parse_depends("libc6 (>= 2.2.1), default-mta | mail-transport-agent"),
)

asserts.equals(
env,
[
{"name": "libluajit5.1-dev", "version": None, "arch": ["i386", "amd64", "kfreebsd-i386", "armel", "armhf", "powerpc", "mips"]},
{"name": "liblua5.1-dev", "version": None, "arch": ["hurd-i386", "ia64", "kfreebsd-amd64", "s390x", "sparc"]},
", ".join([
"libluajit5.1-dev [i386 amd64 powerpc mips]",
"liblua5.1-dev [hurd-i386 ia64 s390x sparc]",
]): [
{
"name": "libluajit5.1-dev",
"version": None,
"arch": ["i386", "amd64", "powerpc", "mips"],
},
{
"name": "liblua5.1-dev",
"version": None,
"arch": ["hurd-i386", "ia64", "s390x", "sparc"],
},
],
package_resolution.parse_depends("libluajit5.1-dev [i386 amd64 kfreebsd-i386 armel armhf powerpc mips], liblua5.1-dev [hurd-i386 ia64 kfreebsd-amd64 s390x sparc]"),
)

asserts.equals(
env,
[
" | ".join([
"emacs",
"emacsen, make, debianutils (>= 1.7)",
]): [
[
{"name": "emacs", "version": None, "arch": None},
{"name": "emacsen", "version": None, "arch": None},
],
{"name": "make", "version": None, "arch": None},
{"name": "debianutils", "version": (">=", "1.7"), "arch": None},
],
package_resolution.parse_depends("emacs | emacsen, make, debianutils (>= 1.7)"),
)

asserts.equals(
env,
[
{"name": "libcap-dev", "version": None, "arch": ["!kfreebsd-i386", "!kfreebsd-amd64", "!hurd-i386"]},
", ".join([
"libcap-dev [!kfreebsd-i386 !hurd-i386]",
"autoconf",
"debhelper (>> 5.0.0)",
"file",
"libc6 (>= 2.7-1)",
"libpaper1",
"psutils",
]): [
{"name": "libcap-dev", "version": None, "arch": ["!kfreebsd-i386", "!hurd-i386"]},
{"name": "autoconf", "version": None, "arch": None},
{"name": "debhelper", "version": (">>", "5.0.0"), "arch": None},
{"name": "file", "version": None, "arch": None},
{"name": "libc6", "version": (">=", "2.7-1"), "arch": None},
{"name": "libpaper1", "version": None, "arch": None},
{"name": "psutils", "version": None, "arch": None},
],
package_resolution.parse_depends("libcap-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], autoconf, debhelper (>> 5.0.0), file, libc6 (>= 2.7-1), libpaper1, psutils"),
)

asserts.equals(
env,
[
"python3:any": [
{"name": "python3", "version": None, "arch": ["any"]},
],
package_resolution.parse_depends("python3:any"),
)

asserts.equals(
env,
[
" | ".join([
"gcc-i686-linux-gnu (>= 4:10.2)",
"gcc:i386, g++-i686-linux-gnu (>= 4:10.2)",
"g++:i386, dpkg-cross",
]): [
[
{"name": "gcc-i686-linux-gnu", "version": (">=", "4:10.2"), "arch": None},
{"name": "gcc", "version": None, "arch": ["i386"]},
Expand All @@ -71,12 +80,11 @@ def _parse_depends_test(ctx):
],
{"name": "dpkg-cross", "version": None, "arch": None},
],
package_resolution.parse_depends("gcc-i686-linux-gnu (>= 4:10.2) | gcc:i386, g++-i686-linux-gnu (>= 4:10.2) | g++:i386, dpkg-cross"),
)

asserts.equals(
env,
[
" | ".join([
"gcc-x86-64-linux-gnu (>= 4:10.2)",
"gcc:amd64, g++-x86-64-linux-gnu (>= 4:10.2)",
"g++:amd64, dpkg-cross",
]): [
[
{"name": "gcc-x86-64-linux-gnu", "version": (">=", "4:10.2"), "arch": None},
{"name": "gcc", "version": None, "arch": ["amd64"]},
Expand All @@ -87,9 +95,15 @@ def _parse_depends_test(ctx):
],
{"name": "dpkg-cross", "version": None, "arch": None},
],
package_resolution.parse_depends("gcc-x86-64-linux-gnu (>= 4:10.2) | gcc:amd64, g++-x86-64-linux-gnu (>= 4:10.2) | g++:amd64, dpkg-cross"),
)
}

for deps, expected in parameters.items():
actual = package_resolution.parse_depends(deps)
asserts.equals(env, expected, actual)

return unittest.end(env)

version_depends_test = unittest.make(_parse_depends_test)
parse_depends_test = unittest.make(_parse_depends_test)

def package_resolution_tests():
parse_depends_test(name = _TEST_SUITE_PREFIX + "parse_depends")
131 changes: 84 additions & 47 deletions apt/tests/version_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,98 @@
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//apt/private:version.bzl", "version")

def _parse_version_test(ctx):
_TEST_SUITE_PREFIX = "version/"

def _parse_test(ctx):
parameters = {
"1:1.4.1-1": ("1", "1.4.1", "1"),
"7.1.ds-1": (None, "7.1.ds", "1"),
"10.11.1.3-2": (None, "10.11.1.3", "2"),
"4.0.1.3.dfsg.1-2": (None, "4.0.1.3.dfsg.1", "2"),
"0.4.23debian1": (None, "0.4.23debian1", None),
"1.2.10+cvs20060429-1": (None, "1.2.10+cvs20060429", "1"),
"0.2.0-1+b1": (None, "0.2.0", "1+b1"),
"4.3.90.1svn-r21976-1": (None, "4.3.90.1svn-r21976", "1"),
"1.5+E-14": (None, "1.5+E", "14"),
"20060611-0.0": (None, "20060611", "0.0"),
"0.52.2-5.1": (None, "0.52.2", "5.1"),
"7.0-035+1": (None, "7.0", "035+1"),
"1.1.0+cvs20060620-1+2.6.15-8": (None, "1.1.0+cvs20060620-1+2.6.15", "8"),
"1.1.0+cvs20060620-1+1.0": (None, "1.1.0+cvs20060620", "1+1.0"),
"4.2.0a+stable-2sarge1": (None, "4.2.0a+stable", "2sarge1"),
"1.8RC4b": (None, "1.8RC4b", None),
"0.9~rc1-1": (None, "0.9~rc1", "1"),
"2:1.0.4+svn26-1ubuntu1": ("2", "1.0.4+svn26", "1ubuntu1"),
"2:1.0.4~rc2-1": ("2", "1.0.4~rc2", "1"),
}

env = unittest.begin(ctx)
asserts.equals(env, version.parse("1:1.4.1-1"), ("1", "1.4.1", "1"))
asserts.equals(env, version.parse("7.1.ds-1"), (None, "7.1.ds", "1"))
asserts.equals(env, version.parse("10.11.1.3-2"), (None, "10.11.1.3", "2"))
asserts.equals(env, version.parse("4.0.1.3.dfsg.1-2"), (None, "4.0.1.3.dfsg.1", "2"))
asserts.equals(env, version.parse("0.4.23debian1"), (None, "0.4.23debian1", None))
asserts.equals(env, version.parse("1.2.10+cvs20060429-1"), (None, "1.2.10+cvs20060429", "1"))
asserts.equals(env, version.parse("0.2.0-1+b1"), (None, "0.2.0", "1+b1"))
asserts.equals(env, version.parse("4.3.90.1svn-r21976-1"), (None, "4.3.90.1svn-r21976", "1"))
asserts.equals(env, version.parse("1.5+E-14"), (None, "1.5+E", "14"))
asserts.equals(env, version.parse("20060611-0.0"), (None, "20060611", "0.0"))
asserts.equals(env, version.parse("0.52.2-5.1"), (None, "0.52.2", "5.1"))
asserts.equals(env, version.parse("7.0-035+1"), (None, "7.0", "035+1"))
asserts.equals(env, version.parse("1.1.0+cvs20060620-1+2.6.15-8"), (None, "1.1.0+cvs20060620-1+2.6.15", "8"))
asserts.equals(env, version.parse("1.1.0+cvs20060620-1+1.0"), (None, "1.1.0+cvs20060620", "1+1.0"))
asserts.equals(env, version.parse("4.2.0a+stable-2sarge1"), (None, "4.2.0a+stable", "2sarge1"))
asserts.equals(env, version.parse("1.8RC4b"), (None, "1.8RC4b", None))
asserts.equals(env, version.parse("0.9~rc1-1"), (None, "0.9~rc1", "1"))
asserts.equals(env, version.parse("2:1.0.4+svn26-1ubuntu1"), ("2", "1.0.4+svn26", "1ubuntu1"))
asserts.equals(env, version.parse("2:1.0.4~rc2-1"), ("2", "1.0.4~rc2", "1"))

for v, expected in parameters.items():
actual = version.parse(v)
asserts.equals(env, actual, expected)

return unittest.end(env)

version_parse_test = unittest.make(_parse_version_test)
parse_test = unittest.make(_parse_test)

def _operators_test(ctx):
parameters = [
("0", version.lt, "a"),
("1.0", version.lt, "1.1"),
("1.2", version.lt, "1.11"),
("1.0-0.1", version.lt, "1.1"),
("1.0-0.1", version.lt, "1.0-1"),
("1.0", version.eq, "1.0"),
("1.0-0.1", version.eq, "1.0-0.1"),
("1:1.0-0.1", version.eq, "1:1.0-0.1"),
("1:1.0", version.eq, "1:1.0"),
("1.0-0.1", version.lt, "1.0-1"),
("1.0final-5sarge1", version.gt, "1.0final-5"),
("1.0final-5", version.gt, "1.0a7-2"),
("0.9.2-5", version.lt, "0.9.2+cvs.1.0.dev.2004.07.28-1.5"),
("1:500", version.lt, "1:5000"),
("100:500", version.gt, "11:5000"),
("1.0.4-2", version.gt, "1.0pre7-2"),
("1.5~rc1", version.lt, "1.5"),
("1.5~rc1", version.lt, "1.5+b1"),
("1.5~rc1", version.lt, "1.5~rc2"),
("1.5~rc1", version.gt, "1.5~dev0"),
]

def _version_compare_test(ctx):
env = unittest.begin(ctx)
asserts.true(env, version.lt("0", "a"))
asserts.true(env, version.lt("1.0", "1.1"))
asserts.true(env, version.lt("1.2", "1.11"))
asserts.true(env, version.lt("1.0-0.1", "1.1"))
asserts.true(env, version.lt("1.0-0.1", "1.0-1"))
asserts.true(env, version.eq("1.0", "1.0"))
asserts.true(env, version.eq("1.0-0.1", "1.0-0.1"))
asserts.true(env, version.eq("1:1.0-0.1", "1:1.0-0.1"))
asserts.true(env, version.eq("1:1.0", "1:1.0"))
asserts.true(env, version.lt("1.0-0.1", "1.0-1"))
asserts.true(env, version.gt("1.0final-5sarge1", "1.0final-5"))
asserts.true(env, version.gt("1.0final-5", "1.0a7-2"))
asserts.true(env, version.lt("0.9.2-5", "0.9.2+cvs.1.0.dev.2004.07.28-1.5"))
asserts.true(env, version.lt("1:500", "1:5000"))
asserts.true(env, version.gt("100:500", "11:5000"))
asserts.true(env, version.gt("1.0.4-2", "1.0pre7-2"))
asserts.true(env, version.lt("1.5~rc1", "1.5"))
asserts.true(env, version.lt("1.5~rc1", "1.5+b1"))
asserts.true(env, version.lt("1.5~rc1", "1.5~rc2"))
asserts.true(env, version.gt("1.5~rc1", "1.5~dev0"))
for va, version_op, vb in parameters:
asserts.true(env, version_op(va, vb))

return unittest.end(env)

version_compare_test = unittest.make(_version_compare_test)
operators_test = unittest.make(_operators_test)

def _sort_test(ctx):
parameters = [
(
["1.5~rc2", "1.0.4-2", "1.5~rc1"],
["1.0.4-2", "1.5~rc1", "1.5~rc2"],
False,
),
(
["1.0a7-2", "1.0final-5sarge1", "1.0final-5"],
["1.0final-5sarge1", "1.0final-5", "1.0a7-2"],
True,
),
]

def _version_sort_test(ctx):
env = unittest.begin(ctx)
asserts.equals(env, version.sort(["1.5~rc2", "1.0.4-2", "1.5~rc1"]), ["1.0.4-2", "1.5~rc1", "1.5~rc2"])
asserts.equals(env, version.sort(["1.0a7-2", "1.0final-5sarge1", "1.0final-5"], reverse = True), ["1.0final-5sarge1", "1.0final-5", "1.0a7-2"])

for to_sort, expected, reversed in parameters:
actual = version.sort(to_sort, reverse = reversed)
asserts.equals(env, expected, actual)

return unittest.end(env)

version_sort_test = unittest.make(_version_sort_test)
sort_test = unittest.make(_sort_test)

def version_tests():
operators_test(name = _TEST_SUITE_PREFIX + "operators")
parse_test(name = _TEST_SUITE_PREFIX + "parse")
sort_test(name = _TEST_SUITE_PREFIX + "sort")
2 changes: 1 addition & 1 deletion e2e/smoke/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PACKAGES = [
"@bullseye//ncurses-base",
"@bullseye//libncurses6",
"@bullseye//tzdata",
"@bullseye//bash",
"@bullseye_nolock//bash",
"@bullseye//coreutils",
"@bullseye//dpkg",
"@bullseye//apt",
Expand Down
10 changes: 10 additions & 0 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ deb_index(
load("@bullseye//:packages.bzl", "bullseye_packages")

bullseye_packages()

deb_index(
name = "bullseye_nolock",
manifest = "//:bullseye.yaml",
nolock = True,
)

load("@bullseye_nolock//:packages.bzl", "bullseye_nolock_packages")

bullseye_nolock_packages()
2 changes: 1 addition & 1 deletion examples/debian_snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PACKAGES = [
"@bullseye//ncurses-base",
"@bullseye//libncurses6",
"@bullseye//tzdata",
"@bullseye//bash",
"@bullseye_nolock//bash",
"@bullseye//coreutils",
"@bullseye//dpkg",
"@bullseye//apt",
Expand Down
Loading

0 comments on commit 6ccc030

Please sign in to comment.