Test that the filer keeps its items in order and exits 2 on a plan it cannot read
This commit is contained in:
@@ -3,7 +3,7 @@ import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from contextlib import redirect_stderr, redirect_stdout
|
||||
|
||||
import file_vulnerabilities
|
||||
|
||||
@@ -99,6 +99,9 @@ class FileItems(unittest.TestCase):
|
||||
)
|
||||
self.assertIn("govulncheck found these in `golang.org/x/text` v0.3.0:\n\n- GO-2026-0003: Panic in x/text\n", todo)
|
||||
self.assertIn("`Next ID = 9`", todo)
|
||||
self.assertEqual([row.split(" | ")[0] for row in rows(todo)], ["| 7", "| 8", "| 5"])
|
||||
details = todo.split("## Details\n\n", 1)[1]
|
||||
self.assertLess(details.index("### 7."), details.index("### 8."))
|
||||
|
||||
def test_a_vulnerability_already_planned_is_not_filed_again(self):
|
||||
planned, _ = file(TODO, *STDLIB)
|
||||
@@ -119,6 +122,14 @@ class FileItems(unittest.TestCase):
|
||||
todo,
|
||||
)
|
||||
|
||||
def test_a_plan_with_no_next_id_is_refused(self):
|
||||
with self.assertRaises(ValueError):
|
||||
file(TODO.replace("`Next ID = 7`", ""), *STDLIB)
|
||||
|
||||
def test_a_plan_with_no_details_heading_is_refused(self):
|
||||
with self.assertRaises(ValueError):
|
||||
file(TODO.replace("## Details", "## Notes"), *STDLIB)
|
||||
|
||||
def test_a_plan_with_no_items_is_refused(self):
|
||||
empty = TODO.split("| 5 |")[0].rstrip("\n") + "\n\n## Details\n"
|
||||
with self.assertRaises(ValueError):
|
||||
@@ -168,6 +179,13 @@ class Main(unittest.TestCase):
|
||||
_, out, _ = self.run_main(*STDLIB, *TEXT)
|
||||
self.assertEqual(out, "3 known vulnerabilities; todo.md items 7, 8 plan the fix.\n")
|
||||
|
||||
def test_a_plan_it_cannot_read_exits_2(self):
|
||||
with open("todo.md", "w", encoding="utf-8") as f:
|
||||
f.write(TODO.replace("`Next ID = 7`", ""))
|
||||
with redirect_stderr(io.StringIO()) as err:
|
||||
self.assertEqual(self.run_main(*STDLIB)[:2], (2, ""))
|
||||
self.assertEqual(err.getvalue(), "todo.md has no `Next ID = N` line to number the item by\n")
|
||||
|
||||
def test_one_finding_already_planned_still_fails(self):
|
||||
self.run_main(*TEXT)
|
||||
self.assertEqual(self.run_main(*TEXT)[:2], (1, "1 known vulnerability, already planned in todo.md.\n"))
|
||||
|
||||
Reference in New Issue
Block a user