aboutsummaryrefslogtreecommitdiff
path: root/tests/deb/deb_tests.bzl
blob: 0227d0518ed78e2e8d2d0defc42846f61d599f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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(),
    },
)