Coverage for tests / unit / tools / cargo_deny / test_cargo_deny_plugin.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Unit tests for cargo-deny plugin.""" 

2 

3from __future__ import annotations 

4 

5import pytest 

6from assertpy import assert_that 

7 

8from lintro.enums.tool_type import ToolType 

9from lintro.tools.definitions.cargo_deny import CargoDenyPlugin 

10 

11 

12@pytest.fixture 

13def cargo_deny_plugin() -> CargoDenyPlugin: 

14 """Provide a CargoDenyPlugin instance for testing. 

15 

16 Returns: 

17 A CargoDenyPlugin instance. 

18 """ 

19 return CargoDenyPlugin() 

20 

21 

22def test_definition_name(cargo_deny_plugin: CargoDenyPlugin) -> None: 

23 """Verify the tool name. 

24 

25 Args: 

26 cargo_deny_plugin: The plugin instance. 

27 """ 

28 assert_that(cargo_deny_plugin.definition.name).is_equal_to("cargo_deny") 

29 

30 

31def test_definition_can_fix(cargo_deny_plugin: CargoDenyPlugin) -> None: 

32 """Verify the tool cannot fix issues. 

33 

34 Args: 

35 cargo_deny_plugin: The plugin instance. 

36 """ 

37 assert_that(cargo_deny_plugin.definition.can_fix).is_false() 

38 

39 

40def test_definition_tool_type(cargo_deny_plugin: CargoDenyPlugin) -> None: 

41 """Verify the tool type is SECURITY | INFRASTRUCTURE. 

42 

43 Args: 

44 cargo_deny_plugin: The plugin instance. 

45 """ 

46 expected_type = ToolType.SECURITY | ToolType.INFRASTRUCTURE 

47 assert_that(cargo_deny_plugin.definition.tool_type).is_equal_to(expected_type) 

48 

49 

50def test_definition_file_patterns(cargo_deny_plugin: CargoDenyPlugin) -> None: 

51 """Verify the file patterns. 

52 

53 Args: 

54 cargo_deny_plugin: The plugin instance. 

55 """ 

56 patterns = cargo_deny_plugin.definition.file_patterns 

57 assert_that(patterns).contains("Cargo.toml") 

58 assert_that(patterns).contains("deny.toml") 

59 

60 

61def test_definition_priority(cargo_deny_plugin: CargoDenyPlugin) -> None: 

62 """Verify the priority is 90. 

63 

64 Args: 

65 cargo_deny_plugin: The plugin instance. 

66 """ 

67 assert_that(cargo_deny_plugin.definition.priority).is_equal_to(90) 

68 

69 

70def test_definition_timeout(cargo_deny_plugin: CargoDenyPlugin) -> None: 

71 """Verify the default timeout is 60. 

72 

73 Args: 

74 cargo_deny_plugin: The plugin instance. 

75 """ 

76 assert_that(cargo_deny_plugin.definition.default_timeout).is_equal_to(60) 

77 

78 

79def test_definition_native_configs(cargo_deny_plugin: CargoDenyPlugin) -> None: 

80 """Verify the native config files. 

81 

82 Args: 

83 cargo_deny_plugin: The plugin instance. 

84 """ 

85 assert_that(cargo_deny_plugin.definition.native_configs).contains("deny.toml") 

86 

87 

88def test_fix_raises_not_implemented(cargo_deny_plugin: CargoDenyPlugin) -> None: 

89 """Verify fix raises NotImplementedError. 

90 

91 Args: 

92 cargo_deny_plugin: The plugin instance. 

93 """ 

94 with pytest.raises(NotImplementedError) as exc_info: 

95 cargo_deny_plugin.fix(["."], {}) 

96 assert_that(str(exc_info.value)).contains("cannot automatically fix") 

97 

98 

99def test_set_options_timeout(cargo_deny_plugin: CargoDenyPlugin) -> None: 

100 """Verify timeout option can be set. 

101 

102 Args: 

103 cargo_deny_plugin: The plugin instance. 

104 """ 

105 cargo_deny_plugin.set_options(timeout=120) 

106 assert_that(cargo_deny_plugin.options.get("timeout")).is_equal_to(120) 

107 

108 

109def test_set_options_invalid_timeout(cargo_deny_plugin: CargoDenyPlugin) -> None: 

110 """Verify invalid timeout raises ValueError. 

111 

112 Args: 

113 cargo_deny_plugin: The plugin instance. 

114 """ 

115 with pytest.raises(ValueError): 

116 cargo_deny_plugin.set_options(timeout=-1)