Skip to content

Commit

Permalink
Add: Unit tests for new check
Browse files Browse the repository at this point in the history
  • Loading branch information
n-thumann committed Mar 3, 2025
1 parent 566f51a commit e9c3014
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/plugins/test_creation_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,43 @@ def test_wrong_length(self):
"False or incorrectly formatted creation_date.",
results[0].message,
)

def test_creation_date_greater_than_last_modification(self):
path = Path("some/file.nasl")
content = (
' script_tag(name:"creation_date", value:"2025-01-01 00:00:01 '
'+0200 (Wed, 01 Jan 2025)");\n'
' script_tag(name:"last_modification", value:"2025-01-01 00:00:00 '
'+0200 (Wed, 01 Jan 2025)");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckCreationDate(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 1)

self.assertIsInstance(results[0], LinterError)
self.assertEqual(
"The creation_date must not be greater than the last modification date.",
results[0].message,
)

def test_creation_date_equal_last_modification(self):
path = Path("some/file.nasl")
content = (
' script_tag(name:"creation_date", value:"2025-01-01 00:00:00 '
'+0200 (Wed, 01 Jan 2025)");\n'
' script_tag(name:"last_modification", value:"2025-01-01 00:00:00 '
'+0200 (Wed, 01 Jan 2025)");\n'
)
fake_context = self.create_file_plugin_context(
nasl_file=path, file_content=content
)
plugin = CheckCreationDate(fake_context)

results = list(plugin.run())

self.assertEqual(len(results), 0)

0 comments on commit e9c3014

Please sign in to comment.