import pytest

from debputy.filesystem_scan import VirtualTestPath
from debputy.util import apply_symbolic_mode


@pytest.mark.parametrize(
    "base_mode,is_dir,symbolic_mode,expected",
    [
        (0o0644, False, "u+rwX,og=rX", 0o0644),
        (0o0000, False, "u+rwX,og=rX", 0o0644),
        (0o0400, True, "u+rwX,og=rX", 0o0755),
        (0o0000, True, "u+rwX,og=rX", 0o0755),
        (0o2400, False, "u+rwxs,og=rx", 0o04755),
        (0o7400, False, "u=rwX,og=rX", 0o0644),
        (0o0641, False, "u=rwX,og=rX", 0o0755),
        (0o4755, False, "a-x", 0o04644),
    ],
)
def test_generate_deb_filename(base_mode, is_dir, symbolic_mode, expected):
    path_obj = VirtualTestPath("foo", None, is_dir=is_dir)
    actual = apply_symbolic_mode(path_obj, base_mode, symbolic_mode)
    assert oct(actual)[2:] == oct(expected)[2:]
